Skip to content
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
Create less tmp dirs, test FileNotFoundError attrs too
  • Loading branch information
6t8k committed Jan 31, 2023
commit 74a7fe4c70c959c543fc391200885b6e5ac4e98f
30 changes: 18 additions & 12 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,38 +1670,44 @@ def test_make_tarfile_rootdir_nodir(self):
self.addCleanup(os_helper.unlink, f'{TESTFN}.tar')
for dry_run in (False, True):
with self.subTest(dry_run=dry_run):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
tmp_dir = self.mkdtemp()
nonexisting_file = os.path.join(tmp_dir, 'nonexisting')
with self.assertRaises(FileNotFoundError) as cm:
make_archive(TESTFN, 'tar', nonexisting_file, dry_run=dry_run)
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(cm.exception.filename, nonexisting_file)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=tmp_dir)
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError) as cm:
make_archive(TESTFN, 'tar', tmp_file, dry_run=dry_run)
self.assertEqual(cm.exception.errno, errno.ENOTDIR)
self.assertEqual(cm.exception.filename, tmp_file)
self.assertFalse(os.path.exists(f'{TESTFN}.tar'))

nonexisting_file = os.path.join(self.mkdtemp(), 'nonexisting')
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'tar', nonexisting_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(os_helper.unlink, f'{TESTFN}.zip')
for dry_run in (False, True):
with self.subTest(dry_run=dry_run):
tmp_fd, tmp_file = tempfile.mkstemp(dir=self.mkdtemp())
tmp_dir = self.mkdtemp()
nonexisting_file = os.path.join(tmp_dir, 'nonexisting')
with self.assertRaises(FileNotFoundError) as cm:
make_archive(TESTFN, 'zip', nonexisting_file, dry_run=dry_run)
self.assertEqual(cm.exception.errno, errno.ENOENT)
self.assertEqual(cm.exception.filename, nonexisting_file)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

tmp_fd, tmp_file = tempfile.mkstemp(dir=tmp_dir)
os.close(tmp_fd)
with self.assertRaises(NotADirectoryError) as cm:
make_archive(TESTFN, 'zip', tmp_file, dry_run=dry_run)
self.assertEqual(cm.exception.errno, errno.ENOTDIR)
self.assertEqual(cm.exception.filename, tmp_file)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

nonexisting_file = os.path.join(self.mkdtemp(), 'nonexisting')
with self.assertRaises(FileNotFoundError):
make_archive(TESTFN, 'zip', nonexisting_file, dry_run=dry_run)
self.assertFalse(os.path.exists(f'{TESTFN}.zip'))

### shutil.unpack_archive

def check_unpack_archive(self, format):
Expand Down