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