8000 bpo-45234: Fix FileNotFound exception raised instead of IsADirectoryError in shutil.copyfile() by akulakov · Pull Request #28421 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45234: Fix FileNotFound exception raised instead of IsADirectoryError in shutil.copyfile() #28421

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 4 commits into from
Sep 21, 2021
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
extract copy and copy2 tests into separate methods
  • Loading branch information
akulakov committed Sep 18, 2021
commit b154282098acbb0714fced35d0c7d266bf13a5e1
28 changes: 22 additions & 6 deletions Lib/test/test_shutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,28 @@ def test_copy_return_value(self):
rv = fn(src, os.path.join(dst_dir, 'bar'))
self.assertEqual(rv, os.path.join(dst_dir, 'bar'))

def test_copy_dir(self):
self._test_copy_dir(shutil.copy)

def test_copy2_dir(self):
self._test_copy_dir(shutil.copy2)

def _test_copy_dir(self, copy_func):
src_dir = self.mkdtemp()
src_file = os.path.join(src_dir, 'foo')
dir2 = self.mkdtemp()
dst = os.path.join(src_dir, 'does_not_exist/')
write_file(src_file, 'foo')
if sys.platform == "win32":
err = PermissionError
else:
err = IsADirectoryError
self.assertRaises(err, copy_func, dir2, src_dir)

# raise *err* because of src rather than FileNotFoundError because of dst
self.assertRaises(err, copy_func, dir2, dst)
copy_func(src_file, dir2) # should not raise exceptions

### shutil.copyfile

@os_helper.skip_unless_symlink
Expand Down Expand Up @@ -1276,12 +1298,6 @@ def test_copyfile_copy_dir(self):
self.assertRaises(err, shutil.copyfile, src_dir, dst)
self.assertRaises(err, shutil.copyfile, src_file, src_dir)
self.assertRaises(err, shutil.copyfile, dir2, src_dir)
self.assertRaises(err, shutil.copy, dir2, src_dir)
self.assertRaises(err, shutil.copy2, dir2, src_dir)

# raise *err* because of src rather than FileNotFoundError because of dst
self.assertRaises(err, shutil.copy, dir2, dst)
shutil.copy(src_file, dir2) # should not raise exceptions


class TestArchives(BaseTest, unittest.TestCase):
Expand Down
0