[3.9] bpo-43219: shutil.copyfile, raise a less confusing exception instead of IsADirectoryError (GH-27049) (GH-27082)

Fixes the misleading IsADirectoryError to be FileNotFoundError.
(cherry picked from commit 248173cc04)


Co-authored-by: andrei kulakov <andrei.avk@gmail.com>

Automerge-Triggered-By: GH:gpshead
This commit is contained in:
Miss Islington (bot) 2021-07-09 21:13:59 -07:00 committed by GitHub
parent 302df02789
commit c89f0b2587
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 20 deletions

View file

@ -1243,6 +1243,15 @@ class TestCopy(BaseTest, unittest.TestCase):
# Make sure file is not corrupted.
self.assertEqual(read_file(src_file), 'foo')
@unittest.skipIf(MACOS or _winapi, 'On MACOS and Windows the errors are not confusing (though different)')
def test_copyfile_nonexistent_dir(self):
# Issue 43219
src_dir = self.mkdtemp()
src_file = os.path.join(src_dir, 'foo')
dst = os.path.join(src_dir, 'does_not_exist/')
write_file(src_file, 'foo')
self.assertRaises(FileNotFoundError, shutil.copyfile, src_file, dst)
class TestArchives(BaseTest, unittest.TestCase):