[Python-checkins] cpython (merge 3.3 -> default): Issue #1666318: Add a test that shutil.copytree() retains directory permissions.
antoine.pitrou
python-checkins at python.org
Fri Aug 16 19:36:32 CEST 2013
http://hg.python.org/cpython/rev/8906713d5704
changeset: 85194:8906713d5704
parent: 85191:04b50a1eb013
parent: 85193:c388e93879c4
user: Antoine Pitrou <solipsis at pitrou.net>
date: Fri Aug 16 19:36:18 2013 +0200
summary:
Issue #1666318: Add a test that shutil.copytree() retains directory permissions.
Patch by Catherine Devlin.
files:
Lib/test/test_shutil.py | 26 ++++++++++++++++++++++++++
Misc/NEWS | 3 +++
2 files changed, 29 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -727,6 +727,32 @@
shutil.rmtree(src_dir)
shutil.rmtree(os.path.dirname(dst_dir))
+ def test_copytree_retains_permissions(self):
+ tmp_dir = tempfile.mkdtemp()
+ src_dir = os.path.join(tmp_dir, 'source')
+ os.mkdir(src_dir)
+ dst_dir = os.path.join(tmp_dir, 'destination')
+ self.addCleanup(shutil.rmtree, tmp_dir)
+
+ os.chmod(src_dir, 0o777)
+ write_file((src_dir, 'permissive.txt'), '123')
+ os.chmod(os.path.join(src_dir, 'permissive.txt'), 0o777)
+ write_file((src_dir, 'restrictive.txt'), '456')
+ os.chmod(os.path.join(src_dir, 'restrictive.txt'), 0o600)
+ restrictive_subdir = tempfile.mkdtemp(dir=src_dir)
+ os.chmod(restrictive_subdir, 0o600)
+
+ shutil.copytree(src_dir, dst_dir)
+ self.assertEquals(os.stat(src_dir).st_mode, os.stat(dst_dir).st_mode)
+ self.assertEquals(os.stat(os.path.join(src_dir, 'permissive.txt')).st_mode,
+ os.stat(os.path.join(dst_dir, 'permissive.txt')).st_mode)
+ self.assertEquals(os.stat(os.path.join(src_dir, 'restrictive.txt')).st_mode,
+ os.stat(os.path.join(dst_dir, 'restrictive.txt')).st_mode)
+ restrictive_subdir_dst = os.path.join(dst_dir,
+ os.path.split(restrictive_subdir)[1])
+ self.assertEquals(os.stat(restrictive_subdir).st_mode,
+ os.stat(restrictive_subdir_dst).st_mode)
+
@unittest.skipUnless(hasattr(os, 'link'), 'requires os.link')
def test_dont_copy_file_onto_link_to_itself(self):
# Temporarily disable test on Windows.
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -682,6 +682,9 @@
Tests
-----
+- Issue #1666318: Add a test that shutil.copytree() retains directory
+ permissions. Patch by Catherine Devlin.
+
- Issue #18273: move the tests in Lib/test/json_tests to Lib/test/test_json
and make them discoverable by unittest. Patch by Zachary Ware.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list