(self)
| 826 | self.assertEqual(dst_stat.st_flags, src_stat.st_flags) |
| 827 | |
| 828 | def test_copytree_with_exclude(self): |
| 829 | # creating data |
| 830 | join = os.path.join |
| 831 | exists = os.path.exists |
| 832 | src_dir = self.mkdtemp() |
| 833 | try: |
| 834 | dst_dir = join(self.mkdtemp(), 'destination') |
| 835 | create_file((src_dir, 'test.txt'), '123') |
| 836 | create_file((src_dir, 'test.tmp'), '123') |
| 837 | os.mkdir(join(src_dir, 'test_dir')) |
| 838 | create_file((src_dir, 'test_dir', 'test.txt'), '456') |
| 839 | os.mkdir(join(src_dir, 'test_dir2')) |
| 840 | create_file((src_dir, 'test_dir2', 'test.txt'), '456') |
| 841 | os.mkdir(join(src_dir, 'test_dir2', 'subdir')) |
| 842 | os.mkdir(join(src_dir, 'test_dir2', 'subdir2')) |
| 843 | create_file((src_dir, 'test_dir2', 'subdir', 'test.txt'), '456') |
| 844 | create_file((src_dir, 'test_dir2', 'subdir2', 'test.py'), '456') |
| 845 | |
| 846 | # testing glob-like patterns |
| 847 | try: |
| 848 | patterns = shutil.ignore_patterns('*.tmp', 'test_dir2') |
| 849 | shutil.copytree(src_dir, dst_dir, ignore=patterns) |
| 850 | # checking the result: some elements should not be copied |
| 851 | self.assertTrue(exists(join(dst_dir, 'test.txt'))) |
| 852 | self.assertFalse(exists(join(dst_dir, 'test.tmp'))) |
| 853 | self.assertFalse(exists(join(dst_dir, 'test_dir2'))) |
| 854 | finally: |
| 855 | shutil.rmtree(dst_dir) |
| 856 | try: |
| 857 | patterns = shutil.ignore_patterns('*.tmp', 'subdir*') |
| 858 | shutil.copytree(src_dir, dst_dir, ignore=patterns) |
| 859 | # checking the result: some elements should not be copied |
| 860 | self.assertFalse(exists(join(dst_dir, 'test.tmp'))) |
| 861 | self.assertFalse(exists(join(dst_dir, 'test_dir2', 'subdir2'))) |
| 862 | self.assertFalse(exists(join(dst_dir, 'test_dir2', 'subdir'))) |
| 863 | finally: |
| 864 | shutil.rmtree(dst_dir) |
| 865 | |
| 866 | # testing callable-style |
| 867 | try: |
| 868 | def _filter(src, names): |
| 869 | res = [] |
| 870 | for name in names: |
| 871 | path = os.path.join(src, name) |
| 872 | |
| 873 | if (os.path.isdir(path) and |
| 874 | path.split()[-1] == 'subdir'): |
| 875 | res.append(name) |
| 876 | elif os.path.splitext(path)[-1] in ('.py'): |
| 877 | res.append(name) |
| 878 | return res |
| 879 | |
| 880 | shutil.copytree(src_dir, dst_dir, ignore=_filter) |
| 881 | |
| 882 | # checking the result: some elements should not be copied |
| 883 | self.assertFalse(exists(join(dst_dir, 'test_dir2', 'subdir2', |
| 884 | 'test.py'))) |
| 885 | self.assertFalse(exists(join(dst_dir, 'test_dir2', 'subdir'))) |
nothing calls this directly
no test coverage detected