Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(24)

Side by Side Diff: Lib/test/test_shutil.py

Issue 21697: shutil.copytree() handles symbolic directory incorrectly
Patch Set: Created 4 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/shutil.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2003 Python Software Foundation 1 # Copyright (C) 2003 Python Software Foundation
2 2
3 import unittest 3 import unittest
4 import unittest.mock 4 import unittest.mock
5 import shutil 5 import shutil
6 import tempfile 6 import tempfile
7 import sys 7 import sys
8 import stat 8 import stat
9 import os 9 import os
10 import os.path 10 import os.path
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 893
894 # a dangling symlink is ignored with the proper flag 894 # a dangling symlink is ignored with the proper flag
895 dst_dir = os.path.join(self.mkdtemp(), 'destination2') 895 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
896 shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True) 896 shutil.copytree(src_dir, dst_dir, ignore_dangling_symlinks=True)
897 self.assertNotIn('test.txt', os.listdir(dst_dir)) 897 self.assertNotIn('test.txt', os.listdir(dst_dir))
898 898
899 # a dangling symlink is copied if symlinks=True 899 # a dangling symlink is copied if symlinks=True
900 dst_dir = os.path.join(self.mkdtemp(), 'destination3') 900 dst_dir = os.path.join(self.mkdtemp(), 'destination3')
901 shutil.copytree(src_dir, dst_dir, symlinks=True) 901 shutil.copytree(src_dir, dst_dir, symlinks=True)
902 self.assertIn('test.txt', os.listdir(dst_dir)) 902 self.assertIn('test.txt', os.listdir(dst_dir))
903
904 @support.skip_unless_symlink
905 def test_copytree_symlink_dir(self):
906 src_dir = self.mkdtemp()
907 dst_dir = os.path.join(self.mkdtemp(), 'destination')
908 os.mkdir(os.path.join(src_dir, 'real_dir'))
909 with open(os.path.join(src_dir, 'real_dir', 'test.txt'), 'w'):
910 pass
911 os.symlink(os.path.join(src_dir, 'real_dir'),
912 os.path.join(src_dir, 'link_to_dir'),
913 target_is_directory=True)
914 shutil.copytree(src_dir, dst_dir, symlinks=False)
915
916 assert not os.path.islink(os.path.join(dst_dir, 'link_to_dir'))
917 self.assertIn("test.txt", os.listdir(os.path.join(dst_dir, 'link_to_dir' )))
918
919 dst_dir = os.path.join(self.mkdtemp(), 'destination2')
920 shutil.copytree(src_dir, dst_dir, symlinks=True)
921 assert os.path.islink(os.path.join(dst_dir, 'link_to_dir'))
922 self.assertIn("test.txt", os.listdir(os.path.join(dst_dir, 'link_to_dir' )))
903 923
904 def _copy_file(self, method): 924 def _copy_file(self, method):
905 fname = 'test.txt' 925 fname = 'test.txt'
906 tmpdir = self.mkdtemp() 926 tmpdir = self.mkdtemp()
907 write_file((tmpdir, fname), 'xxx') 927 write_file((tmpdir, fname), 'xxx')
908 file1 = os.path.join(tmpdir, fname) 928 file1 = os.path.join(tmpdir, fname)
909 tmpdir2 = self.mkdtemp() 929 tmpdir2 = self.mkdtemp()
910 method(file1, tmpdir2) 930 method(file1, tmpdir2)
911 file2 = os.path.join(tmpdir2, fname) 931 file2 = os.path.join(tmpdir2, fname)
912 return (file1, file2) 932 return (file1, file2)
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 'register_unpack_format', 'unregister_unpack_format', 1851 'register_unpack_format', 'unregister_unpack_format',
1832 'unpack_archive', 'ignore_patterns', 'chown', 'which', 1852 'unpack_archive', 'ignore_patterns', 'chown', 'which',
1833 'get_terminal_size', 'SameFileError'] 1853 'get_terminal_size', 'SameFileError']
1834 if hasattr(os, 'statvfs') or os.name == 'nt': 1854 if hasattr(os, 'statvfs') or os.name == 'nt':
1835 target_api.append('disk_usage') 1855 target_api.append('disk_usage')
1836 self.assertEqual(set(shutil.__all__), set(target_api)) 1856 self.assertEqual(set(shutil.__all__), set(target_api))
1837 1857
1838 1858
1839 if __name__ == '__main__': 1859 if __name__ == '__main__':
1840 unittest.main() 1860 unittest.main()
OLDNEW
« no previous file with comments | « Lib/shutil.py ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+