| 3470 | can_symlink = PathTest.can_symlink |
| 3471 | |
| 3472 | def setUp(self): |
| 3473 | name = self.id().split('.')[-1] |
| 3474 | if name in _tests_needing_symlinks and not self.can_symlink: |
| 3475 | self.skipTest('requires symlinks') |
| 3476 | self.walk_path = self.cls(self.base, "TEST1") |
| 3477 | self.sub1_path = self.walk_path / "SUB1" |
| 3478 | self.sub11_path = self.sub1_path / "SUB11" |
| 3479 | self.sub2_path = self.walk_path / "SUB2" |
| 3480 | self.link_path = self.sub2_path / "link" |
| 3481 | self.sub2_tree = (self.sub2_path, [], ["tmp3"]) |
| 3482 | |
| 3483 | # Build: |
| 3484 | # TESTFN/ |
| 3485 | # TEST1/ a file kid and two directory kids |
| 3486 | # tmp1 |
| 3487 | # SUB1/ a file kid and a directory kid |
| 3488 | # tmp2 |
| 3489 | # SUB11/ no kids |
| 3490 | # SUB2/ a file kid and a dirsymlink kid |
| 3491 | # tmp3 |
| 3492 | # link/ a symlink to TEST2 |
| 3493 | # broken_link |
| 3494 | # broken_link2 |
| 3495 | # TEST2/ |
| 3496 | # tmp4 a lone file |
| 3497 | t2_path = self.cls(self.base, "TEST2") |
| 3498 | os.makedirs(self.sub11_path) |
| 3499 | os.makedirs(self.sub2_path) |
| 3500 | os.makedirs(t2_path) |
| 3501 | |
| 3502 | tmp1_path = self.walk_path / "tmp1" |
| 3503 | tmp2_path = self.sub1_path / "tmp2" |
| 3504 | tmp3_path = self.sub2_path / "tmp3" |
| 3505 | tmp4_path = self.cls(self.base, "TEST2", "tmp4") |
| 3506 | for path in tmp1_path, tmp2_path, tmp3_path, tmp4_path: |
| 3507 | with open(path, "w", encoding='utf-8') as f: |
| 3508 | f.write(f"I'm {path} and proud of it. Blame test_pathlib.\n") |
| 3509 | |
| 3510 | if self.can_symlink: |
| 3511 | broken_link_path = self.sub2_path / "broken_link" |
| 3512 | broken_link2_path = self.sub2_path / "broken_link2" |
| 3513 | os.symlink(t2_path, self.link_path, target_is_directory=True) |
| 3514 | os.symlink('broken', broken_link_path) |
| 3515 | os.symlink(os.path.join('tmp3', 'broken'), broken_link2_path) |
| 3516 | self.sub2_tree = (self.sub2_path, [], ["broken_link", "broken_link2", "link", "tmp3"]) |
| 3517 | sub21_path= self.sub2_path / "SUB21" |
| 3518 | tmp5_path = sub21_path / "tmp3" |
| 3519 | broken_link3_path = self.sub2_path / "broken_link3" |
| 3520 | |
| 3521 | os.makedirs(sub21_path) |
| 3522 | tmp5_path.write_text("I am tmp5, blame test_pathlib.") |
| 3523 | if self.can_symlink: |
| 3524 | os.symlink(tmp5_path, broken_link3_path) |
| 3525 | self.sub2_tree[2].append('broken_link3') |
| 3526 | self.sub2_tree[2].sort() |
| 3527 | os.chmod(sub21_path, 0) |
| 3528 | try: |
| 3529 | os.listdir(sub21_path) |