Skip to content

Commit 97bd578

Browse files
committed
Add tests to ensure no left over if shutil.move fails other than EXDEV
1 parent 37e2543 commit 97bd578

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎Lib/test/test_shutil.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3196,6 +3196,29 @@ def test_move_dir_permission_denied(self):
31963196
os.lchflags(TESTFN_DST, stat.UF_OPAQUE)
31973197
os_helper.rmtree(TESTFN_DST)
31983198

3199+
def test_no_copied_file_left_not_EXDEV(self):
3200+
os.chmod(self.src_dir, 0o500)
3201+
new_file = os.path.join(self.dst_dir, "bar")
3202+
self.assertRaises(PermissionError, shutil.move, self.src_file, new_file)
3203+
self.assertFalse(os.path.exists(new_file))
3204+
3205+
def test_no_copied_dir_left_not_EXDEV(self):
3206+
subdir = os.path.join(self.src_dir, "subdir")
3207+
os.mkdir(subdir)
3208+
create_file(os.path.join(subdir, "foo2"), b"another spam")
3209+
os.chmod(self.src_dir, 0o500)
3210+
new_dir = os.path.join(self.dst_dir, "new_dir")
3211+
self.assertRaises(PermissionError, shutil.move, subdir, new_dir)
3212+
self.assertFalse(os.path.exists(new_dir))
3213+
3214+
def test_no_copied_symlink_left_not_EXDEV(self):
3215+
old_link = os.path.join(self.src_dir, "bar")
3216+
os.symlink(self.src_file, old_link)
3217+
os.chmod(self.src_dir, 0o500)
3218+
new_link = os.path.join(self.dst_dir, "new_link")
3219+
self.assertRaises(PermissionError, shutil.move, old_link, new_link)
3220+
self.assertFalse(os.path.exists(new_link))
3221+
31993222

32003223
class TestCopyFile(unittest.TestCase):
32013224

0 commit comments

Comments
 (0)