cpython: c388e93879c4 (original) (raw)
Mercurial > cpython
changeset 85193:c388e93879c4 3.3
Issue #1666318: Add a test that shutil.copytree() retains directory permissions. Patch by Catherine Devlin. [#1666318]
Antoine Pitrou solipsis@pitrou.net | |
---|---|
date | Fri, 16 Aug 2013 19:35:02 +0200 |
parents | 9df0501fab35 |
children | 8906713d5704 477a143bfbfd |
files | Lib/test/test_shutil.py Misc/NEWS |
diffstat | 2 files changed, 29 insertions(+), 0 deletions(-)[+] [-] Lib/test/test_shutil.py 26 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -726,6 +726,32 @@ class TestShutil(unittest.TestCase): shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir))
- def test_copytree_retains_permissions(self):
tmp_dir = tempfile.mkdtemp()[](#l1.8)
src_dir = os.path.join(tmp_dir, 'source')[](#l1.9)
os.mkdir(src_dir)[](#l1.10)
dst_dir = os.path.join(tmp_dir, 'destination')[](#l1.11)
self.addCleanup(shutil.rmtree, tmp_dir)[](#l1.12)
os.chmod(src_dir, 0o777)[](#l1.14)
write_file((src_dir, 'permissive.txt'), '123')[](#l1.15)
os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)[](#l1.16)
write_file((src_dir, 'restrictive.txt'), '456')[](#l1.17)
os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)[](#l1.18)
restrictive_subdir = tempfile.mkdtemp(dir=src_dir)[](#l1.19)
os.chmod(restrictive_subdir, 0o600)[](#l1.20)
shutil.copytree(src_dir, dst_dir)[](#l1.22)
self.assertEquals(os.stat(src_dir).st_mode, os.stat(dst_dir).st_mode)[](#l1.23)
self.assertEquals(os.stat(os.path.join(src_dir, 'permissive.txt')).st_mode,[](#l1.24)
os.stat(os.path.join(dst_dir, 'permissive.txt')).st_mode)[](#l1.25)
self.assertEquals(os.stat(os.path.join(src_dir, 'restrictive.txt')).st_mode,[](#l1.26)
os.stat(os.path.join(dst_dir, 'restrictive.txt')).st_mode)[](#l1.27)
restrictive_subdir_dst = os.path.join(dst_dir,[](#l1.28)
os.path.split(restrictive_subdir)[1])[](#l1.29)
self.assertEquals(os.stat(restrictive_subdir).st_mode,[](#l1.30)
os.stat(restrictive_subdir_dst).st_mode)[](#l1.31)
+ @unittest.skipUnless(hasattr(os, 'link'), 'requires os.link') def test_dont_copy_file_onto_link_to_itself(self): # Temporarily disable test on Windows.
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -258,6 +258,9 @@ IDLE Tests ----- +- Issue #1666318: Add a test that shutil.copytree() retains directory