8000 gh-99203: `shutil.make_archive()`: restore select CPython <= 3.10.5 behavior by 6t8k · Pull Request #99802 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-99203: shutil.make_archive(): restore select CPython <= 3.10.5 behavior #99802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 16, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make use of unittest.TestCase.subTest
  • Loading branch information
6t8k committed Nov 30, 2022
commit 0cfc858903b9d9014f77b9d85238e9b7eacc6480
51 changes: 26 additions & 25 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1669,43 +1669,44 @@ def _unlink_existing_file(self, path):
try:
os.unlink(path)
except FileNotFoundError:
print(f"File {path} not found")
pass

def test_make_tarfile_rootdir_nodir(self):
# GH-99203
self.addCleanup(self._unlink_existing_file, f'{TESTFN}.tar')
for dry_run in (0, True):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError):
make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
os.unlink(tmp_file)
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))
with self.subTest(dry_run=dry_run):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError):
make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
os.unlink(tmp_file)
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

@support.requires_zlib()
def test_make_zipfile_rootdir_nodir(self):
# GH-99203
self.addCleanup(self._unlink_existing_file, f'{TESTFN}.zip')
for dry_run in (0, True):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError):
make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
os.unlink(tmp_file)
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))
with self.subTest(dry_run=dry_run):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError):
make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
os.close(tmp_fd)
os.unlink(tmp_file)
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

### shutil.unpack_archive

Expand Down
0