@@ -731,18 +731,25 @@ def _copy(src, dst):
731
731
732
732
@os_helper .skip_unless_symlink
733
733
def test_copytree_dangling_symlinks (self ):
734
- # a dangling symlink raises an error at the end
735
734
src_dir = self .mkdtemp ()
735
+ valid_file = os .path .join (src_dir , 'test.txt' )
736
+ write_file (valid_file , 'abc' )
737
+ dir_a = os .path .join (src_dir , 'dir_a' )
738
+ os .mkdir (dir_a )
739
+ for d in src_dir , dir_a :
740
+ os .symlink ('IDONTEXIST' , os .path .join (d , 'broken' ))
741
+ os .symlink (valid_file , os .path .join (d , 'valid' ))
742
+
743
+ # A dangling symlink should raise an error.
736
744
dst_dir = os .path .join (self .mkdtemp (), 'destination' )
737
- os .symlink ('IDONTEXIST' , os .path .join (src_dir , 'test.txt' ))
738
- os .mkdir (os .path .join (src_dir , 'test_dir' ))
739
- write_file ((src_dir , 'test_dir' , 'test.txt' ), '456' )
740
745
self .assertRaises (Error , shutil .copytree , src_dir , dst_dir )
741
746
742
- # a dangling symlink is ignored with the proper flag
747
+ # Dangling symlinks should be ignored with the proper flag.
743
748
dst_dir = os .path .join (self .mkdtemp (), 'destination2' )
744
749
shutil .copytree (src_dir , dst_dir , ignore_dangling_symlinks = True )
745
- self .assertNotIn ('test.txt' , os .listdir (dst_dir ))
750
+ for root , dirs , files in os .walk (dst_dir ):
751
+ self .assertNotIn ('broken' , files )
752
+ self .assertIn ('valid' , files )
746
753
747
754
# a dangling symlink is copied if symlinks=True
748
755
dst_dir = os .path .join (self .mkdtemp (), 'destination3' )
0 commit comments