gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 beh… · python/cpython@a86df29

GitHub

@@ -1839,6 +1839,49 @@ def test_register_archive_format(self):

18391839formats= [nameforname, paramsinget_archive_formats()]

18401840self.assertNotIn('xxx', formats)

184118411842+deftest_make_tarfile_rootdir_nodir(self):

1843+# GH-99203

1844+self.addCleanup(os_helper.unlink, f'{TESTFN}.tar')

1845+fordry_runin (False, True):

1846+withself.subTest(dry_run=dry_run):

1847+tmp_dir=self.mkdtemp()

1848+nonexisting_file=os.path.join(tmp_dir, 'nonexisting')

1849+withself.assertRaises(FileNotFoundError) ascm:

1850+make_archive(TESTFN, 'tar', nonexisting_file, dry_run=dry_run)

1851+self.assertEqual(cm.exception.errno, errno.ENOENT)

1852+self.assertEqual(cm.exception.filename, nonexisting_file)

1853+self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

1854+1855+tmp_fd, tmp_file=tempfile.mkstemp(dir=tmp_dir)

1856+os.close(tmp_fd)

1857+withself.assertRaises(NotADirectoryError) ascm:

1858+make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)

1859+self.assertEqual(cm.exception.errno, errno.ENOTDIR)

1860+self.assertEqual(cm.exception.filename, tmp_file)

1861+self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

[email protected]_zlib()

1864+deftest_make_zipfile_rootdir_nodir(self):

1865+# GH-99203

1866+self.addCleanup(os_helper.unlink, f'{TESTFN}.zip')

1867+fordry_runin (False, True):

1868+withself.subTest(dry_run=dry_run):

1869+tmp_dir=self.mkdtemp()

1870+nonexisting_file=os.path.join(tmp_dir, 'nonexisting')

1871+withself.assertRaises(FileNotFoundError) ascm:

1872+make_archive(TESTFN, 'zip', nonexisting_file, dry_run=dry_run)

1873+self.assertEqual(cm.exception.errno, errno.ENOENT)

1874+self.assertEqual(cm.exception.filename, nonexisting_file)

1875+self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

1876+1877+tmp_fd, tmp_file=tempfile.mkstemp(dir=tmp_dir)

1878+os.close(tmp_fd)

1879+withself.assertRaises(NotADirectoryError) ascm:

1880+make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)

1881+self.assertEqual(cm.exception.errno, errno.ENOTDIR)

1882+self.assertEqual(cm.exception.filename, tmp_file)

1883+self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

1884+18421885### shutil.unpack_archive

1843188618441887defcheck_unpack_archive(self, format, **kwargs):