diff options
author | mbarkhau <mbarkhau@gmail.com> | 2020-01-27 23:46:29 (GMT) |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2020-01-27 23:46:29 (GMT) |
commit | cf9d00554715febf21cf94950da4f42723b80498 (patch) | |
tree | 2f44f8f76177e8f95d6b188e0b1390bddd079f35 /Lib/test | |
parent | 7b57b15bd83879ee35f8758a84a7857a9968c145 (diff) | |
download | cpython-cf9d00554715febf21cf94950da4f42723b80498.zip cpython-cf9d00554715febf21cf94950da4f42723b80498.tar.gz cpython-cf9d00554715febf21cf94950da4f42723b80498.tar.bz2 |
[3.8] bpo-39390 shutil: fix argument types for ignore callback (GH-18122)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_shutil.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index 286e333..bcb7e49 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -880,6 +880,48 @@ class TestShutil(unittest.TestCase): shutil.rmtree(src_dir) shutil.rmtree(os.path.dirname(dst_dir)) + def test_copytree_arg_types_of_ignore(self): + join = os.path.join + exists = os.path.exists + + tmp_dir = self.mkdtemp() + src_dir = join(tmp_dir, "source") + + os.mkdir(join(src_dir)) + os.mkdir(join(src_dir, 'test_dir')) + os.mkdir(os.path.join(src_dir, 'test_dir', 'subdir')) + write_file((src_dir, 'test_dir', 'subdir', 'test.txt'), '456') + + invokations = [] + + def _ignore(src, names): + invokations.append(src) + self.assertIsInstance(src, str) + self.assertIsInstance(names, list) + self.assertEqual(len(names), len(set(names))) + for name in names: + self.assertIsInstance(name, str) + return [] + + dst_dir = join(self.mkdtemp(), 'destination') + shutil.copytree(src_dir, dst_dir, ignore=_ignore) + self.assertTrue(exists(join(dst_dir, 'test_dir', 'subdir', + 'test.txt'))) + + dst_dir = join(self.mkdtemp(), 'destination') + shutil.copytree(pathlib.Path(src_dir), dst_dir, ignore=_ignore) + self.assertTrue(exists(join(dst_dir, 'test_dir', 'subdir', + 'test.txt'))) + + dst_dir = join(self.mkdtemp(), 'destination') + src_dir_entry = list(os.scandir(tmp_dir))[0] + self.assertIsInstance(src_dir_entry, os.DirEntry) + shutil.copytree(src_dir_entry, dst_dir, ignore=_ignore) + self.assertTrue(exists(join(dst_dir, 'test_dir', 'subdir', + 'test.txt'))) + + self.assertEqual(len(invokations), 9) + def test_copytree_retains_permissions(self): tmp_dir = tempfile.mkdtemp() src_dir = os.path.join(tmp_dir, 'source') |