| 1478 | return os.walk(top, **kwargs) |
| 1479 | |
| 1480 | def setUp(self): |
| 1481 | join = os.path.join |
| 1482 | self.addCleanup(os_helper.rmtree, os_helper.TESTFN) |
| 1483 | |
| 1484 | # Build: |
| 1485 | # TESTFN/ |
| 1486 | # TEST1/ a file kid and two directory kids |
| 1487 | # tmp1 |
| 1488 | # SUB1/ a file kid and a directory kid |
| 1489 | # tmp2 |
| 1490 | # SUB11/ no kids |
| 1491 | # SUB2/ a file kid and a dirsymlink kid |
| 1492 | # tmp3 |
| 1493 | # SUB21/ not readable |
| 1494 | # tmp5 |
| 1495 | # link/ a symlink to TESTFN.2 |
| 1496 | # broken_link |
| 1497 | # broken_link2 |
| 1498 | # broken_link3 |
| 1499 | # TEST2/ |
| 1500 | # tmp4 a lone file |
| 1501 | self.walk_path = join(os_helper.TESTFN, "TEST1") |
| 1502 | self.sub1_path = join(self.walk_path, "SUB1") |
| 1503 | self.sub11_path = join(self.sub1_path, "SUB11") |
| 1504 | sub2_path = join(self.walk_path, "SUB2") |
| 1505 | sub21_path = join(sub2_path, "SUB21") |
| 1506 | self.tmp1_path = join(self.walk_path, "tmp1") |
| 1507 | tmp2_path = join(self.sub1_path, "tmp2") |
| 1508 | tmp3_path = join(sub2_path, "tmp3") |
| 1509 | tmp5_path = join(sub21_path, "tmp3") |
| 1510 | self.link_path = join(sub2_path, "link") |
| 1511 | t2_path = join(os_helper.TESTFN, "TEST2") |
| 1512 | tmp4_path = join(os_helper.TESTFN, "TEST2", "tmp4") |
| 1513 | self.broken_link_path = join(sub2_path, "broken_link") |
| 1514 | broken_link2_path = join(sub2_path, "broken_link2") |
| 1515 | broken_link3_path = join(sub2_path, "broken_link3") |
| 1516 | |
| 1517 | # Create stuff. |
| 1518 | os.makedirs(self.sub11_path) |
| 1519 | os.makedirs(sub2_path) |
| 1520 | os.makedirs(sub21_path) |
| 1521 | os.makedirs(t2_path) |
| 1522 | |
| 1523 | for path in self.tmp1_path, tmp2_path, tmp3_path, tmp4_path, tmp5_path: |
| 1524 | with open(path, "x", encoding='utf-8') as f: |
| 1525 | f.write("I'm " + path + " and proud of it. Blame test_os.\n") |
| 1526 | |
| 1527 | if os_helper.can_symlink(): |
| 1528 | os.symlink(os.path.abspath(t2_path), self.link_path) |
| 1529 | os.symlink('broken', self.broken_link_path, True) |
| 1530 | os.symlink(join('tmp3', 'broken'), broken_link2_path, True) |
| 1531 | os.symlink(join('SUB21', 'tmp5'), broken_link3_path, True) |
| 1532 | self.sub2_tree = (sub2_path, ["SUB21", "link"], |
| 1533 | ["broken_link", "broken_link2", "broken_link3", |
| 1534 | "tmp3"]) |
| 1535 | else: |
| 1536 | self.sub2_tree = (sub2_path, ["SUB21"], ["tmp3"]) |
| 1537 | |