| 1735 | p = os.path.join(p, 'd') |
| 1736 | |
| 1737 | def test_walk_above_recursion_limit(self): |
| 1738 | depth = 50 |
| 1739 | os.makedirs(os.path.join(self.walk_path, *(['d'] * depth))) |
| 1740 | with infinite_recursion(depth - 5): |
| 1741 | all = list(self.walk(self.walk_path)) |
| 1742 | |
| 1743 | sub2_path = self.sub2_tree[0] |
| 1744 | for root, dirs, files in all: |
| 1745 | if root == sub2_path: |
| 1746 | dirs.sort() |
| 1747 | files.sort() |
| 1748 | |
| 1749 | d_entries = [] |
| 1750 | d_path = self.walk_path |
| 1751 | for _ in range(depth): |
| 1752 | d_path = os.path.join(d_path, "d") |
| 1753 | d_entries.append((d_path, ["d"], [])) |
| 1754 | d_entries[-1][1].clear() |
| 1755 | |
| 1756 | # Sub-sequences where the order is known |
| 1757 | sections = { |
| 1758 | "SUB1": [ |
| 1759 | (self.sub1_path, ["SUB11"], ["tmp2"]), |
| 1760 | (self.sub11_path, [], []), |
| 1761 | ], |
| 1762 | "SUB2": [self.sub2_tree], |
| 1763 | "d": d_entries, |
| 1764 | } |
| 1765 | |
| 1766 | # The ordering of sub-dirs is arbitrary but determines the order in |
| 1767 | # which sub-sequences appear |
| 1768 | dirs = all[0][1] |
| 1769 | expected = [(self.walk_path, dirs, ["tmp1"])] |
| 1770 | for d in dirs: |
| 1771 | expected.extend(sections[d]) |
| 1772 | |
| 1773 | self.assertEqual(len(all), depth + 4) |
| 1774 | self.assertEqual(sorted(dirs), ["SUB1", "SUB2", "d"]) |
| 1775 | self.assertEqual(all, expected) |
| 1776 | |
| 1777 | |
| 1778 | @unittest.skipUnless(hasattr(os, 'fwalk'), "Test needs os.fwalk()") |