| 1683 | return os.walk(top, **kwargs) |
| 1684 | |
| 1685 | def setUp(self): |
| 1686 | join = os.path.join |
| 1687 | self.addCleanup(os_helper.rmtree, os_helper.TESTFN) |
| 1688 | |
| 1689 | # Build: |
| 1690 | # TESTFN/ |
| 1691 | # TEST1/ a file kid and two directory kids |
| 1692 | # tmp1 |
| 1693 | # SUB1/ a file kid and a directory kid |
| 1694 | # tmp2 |
| 1695 | # SUB11/ no kids |
| 1696 | # SUB2/ a file kid and a dirsymlink kid |
| 1697 | # tmp3 |
| 1698 | # SUB21/ not readable |
| 1699 | # tmp5 |
| 1700 | # link/ a symlink to TESTFN.2 |
| 1701 | # broken_link |
| 1702 | # broken_link2 |
| 1703 | # broken_link3 |
| 1704 | # TEST2/ |
| 1705 | # tmp4 a lone file |
| 1706 | self.walk_path = join(os_helper.TESTFN, "TEST1") |
| 1707 | self.sub1_path = join(self.walk_path, "SUB1") |
| 1708 | self.sub11_path = join(self.sub1_path, "SUB11") |
| 1709 | sub2_path = join(self.walk_path, "SUB2") |
| 1710 | sub21_path = join(sub2_path, "SUB21") |
| 1711 | self.tmp1_path = join(self.walk_path, "tmp1") |
| 1712 | tmp2_path = join(self.sub1_path, "tmp2") |
| 1713 | tmp3_path = join(sub2_path, "tmp3") |
| 1714 | tmp5_path = join(sub21_path, "tmp3") |
| 1715 | self.link_path = join(sub2_path, "link") |
| 1716 | t2_path = join(os_helper.TESTFN, "TEST2") |
| 1717 | tmp4_path = join(os_helper.TESTFN, "TEST2", "tmp4") |
| 1718 | self.broken_link_path = join(sub2_path, "broken_link") |
| 1719 | broken_link2_path = join(sub2_path, "broken_link2") |
| 1720 | broken_link3_path = join(sub2_path, "broken_link3") |
| 1721 | |
| 1722 | # Create stuff. |
| 1723 | os.makedirs(self.sub11_path) |
| 1724 | os.makedirs(sub2_path) |
| 1725 | os.makedirs(sub21_path) |
| 1726 | os.makedirs(t2_path) |
| 1727 | |
| 1728 | for path in self.tmp1_path, tmp2_path, tmp3_path, tmp4_path, tmp5_path: |
| 1729 | with open(path, "x", encoding='utf-8') as f: |
| 1730 | f.write("I'm " + path + " and proud of it. Blame test_os.\n") |
| 1731 | |
| 1732 | if os_helper.can_symlink(): |
| 1733 | os.symlink(os.path.abspath(t2_path), self.link_path) |
| 1734 | os.symlink('broken', self.broken_link_path, True) |
| 1735 | os.symlink(join('tmp3', 'broken'), broken_link2_path, True) |
| 1736 | os.symlink(join('SUB21', 'tmp5'), broken_link3_path, True) |
| 1737 | self.sub2_tree = (sub2_path, ["SUB21", "link"], |
| 1738 | ["broken_link", "broken_link2", "broken_link3", |
| 1739 | "tmp3"]) |
| 1740 | else: |
| 1741 | self.sub2_tree = (sub2_path, ["SUB21"], ["tmp3"]) |
| 1742 | |