@@ -1568,28 +1568,65 @@ def test_tarfile_root_owner(self):
15681568 finally :
15691569 archive .close ()
15701570
1571+ def test_make_archive_cwd_default (self ):
1572+ current_dir = os .getcwd ()
1573+ def archiver (base_name , base_dir , ** kw ):
1574+ self .assertNotIn ('root_dir' , kw )
1575+ self .assertEqual (base_name , 'basename' )
1576+ self .assertEqual (os .getcwd (), current_dir )
1577+ raise RuntimeError ()
1578+
1579+ register_archive_format ('xxx' , archiver , [], 'xxx file' )
1580+ try :
1581+ with no_chdir :
1582+ with self .assertRaises (RuntimeError ):
1583+ make_archive ('basename' , 'xxx' )
1584+ self .assertEqual (os .getcwd (), current_dir )
1585+ finally :
1586+ unregister_archive_format ('xxx' )
1587+
15711588 def test_make_archive_cwd (self ):
15721589 current_dir = os .getcwd ()
15731590 root_dir = self .mkdtemp ()
1574- def _breaks (* args , ** kw ):
1591+ def archiver (base_name , base_dir , ** kw ):
1592+ self .assertNotIn ('root_dir' , kw )
1593+ self .assertEqual (base_name , os .path .join (current_dir , 'basename' ))
1594+ self .assertEqual (os .getcwd (), root_dir )
15751595 raise RuntimeError ()
15761596 dirs = []
15771597 def _chdir (path ):
15781598 dirs .append (path )
15791599 orig_chdir (path )
15801600
1581- register_archive_format ('xxx' , _breaks , [], 'xxx file' )
1601+ register_archive_format ('xxx' , archiver , [], 'xxx file' )
15821602 try :
15831603 with support .swap_attr (os , 'chdir' , _chdir ) as orig_chdir :
1584- try :
1585- make_archive ('xxx' , 'xxx' , root_dir = root_dir )
1586- except Exception :
1587- pass
1604+ with self .assertRaises (RuntimeError ):
1605+ make_archive ('basename' , 'xxx' , root_dir = root_dir )
15881606 self .assertEqual (os .getcwd (), current_dir )
15891607 self .assertEqual (dirs , [root_dir , current_dir ])
15901608 finally :
15911609 unregister_archive_format ('xxx' )
15921610
1611+ def test_make_archive_cwd_supports_root_dir (self ):
1612+ current_dir = os .getcwd ()
1613+ root_dir = self .mkdtemp ()
1614+ def archiver (base_name , base_dir , ** kw ):
1615+ self .assertEqual (base_name , 'basename' )
1616+ self .assertEqual (kw ['root_dir' ], root_dir )
1617+ self .assertEqual (os .getcwd (), current_dir )
1618+ raise RuntimeError ()
1619+ archiver .supports_root_dir = True
1620+
1621+ register_archive_format ('xxx' , archiver , [], 'xxx file' )
1622+ try :
1623+ with no_chdir :
1624+ with self .assertRaises (RuntimeError ):
1625+ make_archive ('basename' , 'xxx' , root_dir = root_dir )
1626+ self .assertEqual (os .getcwd (), current_dir )
1627+ finally :
1628+ unregister_archive_format ('xxx' )
1629+
15931630 def test_make_tarfile_in_curdir (self ):
15941631 # Issue #21280
15951632 root_dir = self .mkdtemp ()
0 commit comments