summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_shutil.py
diff options
context:
space:
mode:
authorjab <jab@users.noreply.github.com>2018-12-28 18:03:40 (GMT)
committerGiampaolo Rodola <g.rodola@gmail.com>2018-12-28 18:03:40 (GMT)
commit9e00d9e88fbf943987e4771c753f5ca8f794103e (patch)
tree4f6e77270b48e56f29fcc1c0dab1151842f2c17a /Lib/test/test_shutil.py
parented57e13df60ce28ba89bd49c9c5a15b1d9bf79c7 (diff)
downloadcpython-9e00d9e88fbf943987e4771c753f5ca8f794103e.zip
cpython-9e00d9e88fbf943987e4771c753f5ca8f794103e.tar.gz
cpython-9e00d9e88fbf943987e4771c753f5ca8f794103e.tar.bz2
bpo-20849: add dirs_exist_ok arg to shutil.copytree (patch by Josh Bronson)
Diffstat (limited to 'Lib/test/test_shutil.py')
-rw-r--r--Lib/test/test_shutil.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
index ec8fcc3..6f22e53 100644
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -691,6 +691,31 @@ class TestShutil(unittest.TestCase):
actual = read_file((dst_dir, 'test_dir', 'test.txt'))
self.assertEqual(actual, '456')
+ def test_copytree_dirs_exist_ok(self):
+ src_dir = tempfile.mkdtemp()
+ dst_dir = tempfile.mkdtemp()
+ self.addCleanup(shutil.rmtree, src_dir)
+ self.addCleanup(shutil.rmtree, dst_dir)
+
+ write_file((src_dir, 'nonexisting.txt'), '123')
+ os.mkdir(os.path.join(src_dir, 'existing_dir'))
+ os.mkdir(os.path.join(dst_dir, 'existing_dir'))
+ write_file((dst_dir, 'existing_dir', 'existing.txt'), 'will be replaced')
+ write_file((src_dir, 'existing_dir', 'existing.txt'), 'has been replaced')
+
+ shutil.copytree(src_dir, dst_dir, dirs_exist_ok=True)
+ self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'nonexisting.txt')))
+ self.assertTrue(os.path.isdir(os.path.join(dst_dir, 'existing_dir')))
+ self.assertTrue(os.path.isfile(os.path.join(dst_dir, 'existing_dir',
+ 'existing.txt')))
+ actual = read_file((dst_dir, 'nonexisting.txt'))
+ self.assertEqual(actual, '123')
+ actual = read_file((dst_dir, 'existing_dir', 'existing.txt'))
+ self.assertEqual(actual, 'has been replaced')
+
+ with self.assertRaises(FileExistsError):
+ shutil.copytree(src_dir, dst_dir, dirs_exist_ok=False)
+
@support.skip_unless_symlink
def test_copytree_symlinks(self):
tmp_dir = self.mkdtemp()