summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-11-07 12:08:39 (GMT)
committerGitHub <noreply@github.com>2022-11-07 12:08:39 (GMT)
commiteb0e942ca86b177c69a8c3da7e20364d606c83cb (patch)
tree11f0b636c142310b05dc8c212e342d88e997d908 /Lib/test/test_shutil.py
parentea2316a220ea5ae5646518e3855ef22b9c84d64d (diff)
downloadcpython-eb0e942ca86b177c69a8c3da7e20364d606c83cb.zip
cpython-eb0e942ca86b177c69a8c3da7e20364d606c83cb.tar.gz
cpython-eb0e942ca86b177c69a8c3da7e20364d606c83cb.tar.bz2
bpo-38523: ignore_dangling_symlinks does not apply recursively (GH-22937)
(cherry picked from commit 5ff81da6d3a8eb01fc5500fd1c9eaa6543286301) Co-authored-by: Zackery Spytz <zspytz@gmail.com>
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py19
1 files changed, 13 insertions, 6 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index 62e9180..0935b60 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -731,18 +731,25 @@ class TestCopyTree(BaseTest, unittest.TestCase):
@os_helper.skip_unless_symlink
def test_copytree_dangling_symlinks(self):
- # a dangling symlink raises an error at the end
src_dir = self.mkdtemp()
+ valid_file = os.path.join(src_dir, 'test.txt')
+ write_file(valid_file, 'abc')
+ dir_a = os.path.join(src_dir, 'dir_a')
+ os.mkdir(dir_a)
+ for d in src_dir, dir_a:
+ os.symlink('IDONTEXIST', os.path.join(d, 'broken'))
+ os.symlink(valid_file, os.path.join(d, 'valid'))
+
+ # A dangling symlink should raise an error.
dst_dir = os.path.join(self.mkdtemp(), 'destination')
- os.symlink('IDONTEXIST', os.path.join(src_dir, 'test.txt'))
- os.mkdir(os.path.join(src_dir, 'test_dir'))
- write_file((src_dir, 'test_dir', 'test.txt'), '456')
self.assertRaises(Error, shutil.copytree, src_dir, dst_dir)
- # a dangling symlink is ignored with the proper flag
+ # Dangling symlinks should be ignored with the proper flag.
dst_dir = os.path.join(self.mkdtemp(), 'destination2')
shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True)
- self.assertNotIn('test.txt', os.listdir(dst_dir))
+ for root, dirs, files in os.walk(dst_dir):
+ self.assertNotIn('broken', files)
+ self.assertIn('valid', files)
# a dangling symlink is copied if symlinks=True
dst_dir = os.path.join(self.mkdtemp(), 'destination3')