(self)
| 795 | |
| 796 | @os_helper.skip_unless_symlink |
| 797 | def test_copytree_symlinks(self): |
| 798 | tmp_dir = self.mkdtemp() |
| 799 | src_dir = os.path.join(tmp_dir, 'src') |
| 800 | dst_dir = os.path.join(tmp_dir, 'dst') |
| 801 | sub_dir = os.path.join(src_dir, 'sub') |
| 802 | os.mkdir(src_dir) |
| 803 | os.mkdir(sub_dir) |
| 804 | create_file((src_dir, 'file.txt'), 'foo') |
| 805 | src_link = os.path.join(sub_dir, 'link') |
| 806 | dst_link = os.path.join(dst_dir, 'sub/link') |
| 807 | os.symlink(os.path.join(src_dir, 'file.txt'), |
| 808 | src_link) |
| 809 | if hasattr(os, 'lchmod'): |
| 810 | os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO) |
| 811 | if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'): |
| 812 | os.lchflags(src_link, stat.UF_NODUMP) |
| 813 | src_stat = os.lstat(src_link) |
| 814 | shutil.copytree(src_dir, dst_dir, symlinks=True) |
| 815 | self.assertTrue(os.path.islink(os.path.join(dst_dir, 'sub', 'link'))) |
| 816 | actual = os.readlink(os.path.join(dst_dir, 'sub', 'link')) |
| 817 | # Bad practice to blindly strip the prefix as it may be required to |
| 818 | # correctly refer to the file, but we're only comparing paths here. |
| 819 | if os.name == 'nt' and actual.startswith('\\\\?\\'): |
| 820 | actual = actual[4:] |
| 821 | self.assertEqual(actual, os.path.join(src_dir, 'file.txt')) |
| 822 | dst_stat = os.lstat(dst_link) |
| 823 | if hasattr(os, 'lchmod'): |
| 824 | self.assertEqual(dst_stat.st_mode, src_stat.st_mode) |
| 825 | if hasattr(os, 'lchflags'): |
| 826 | self.assertEqual(dst_stat.st_flags, src_stat.st_flags) |
| 827 | |
| 828 | def test_copytree_with_exclude(self): |
| 829 | # creating data |
nothing calls this directly
no test coverage detected