Skip to content

Commit da4acf8

Browse files
committed
Re-order test methods.
1 parent 2663285 commit da4acf8

File tree

1 file changed

+78
-78
lines changed

1 file changed

+78
-78
lines changed

Lib/test/test_pathlib/test_pathlib.py

Lines changed: 78 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1425,84 +1425,6 @@ def test_passing_kwargs_errors(self):
14251425
with self.assertRaises(TypeError):
14261426
self.cls(foo="bar")
14271427

1428-
def setUpWalk(self):
1429-
super().setUpWalk()
1430-
sub21_path= self.sub2_path / "SUB21"
1431-
tmp5_path = sub21_path / "tmp3"
1432-
broken_link3_path = self.sub2_path / "broken_link3"
1433-
1434-
os.makedirs(sub21_path)
1435-
tmp5_path.write_text("I am tmp5, blame test_pathlib.")
1436-
if self.can_symlink:
1437-
os.symlink(tmp5_path, broken_link3_path)
1438-
self.sub2_tree[2].append('broken_link3')
1439-
self.sub2_tree[2].sort()
1440-
if not is_emscripten:
1441-
# Emscripten fails with inaccessible directories.
1442-
os.chmod(sub21_path, 0)
1443-
try:
1444-
os.listdir(sub21_path)
1445-
except PermissionError:
1446-
self.sub2_tree[1].append('SUB21')
1447-
else:
1448-
os.chmod(sub21_path, stat.S_IRWXU)
1449-
os.unlink(tmp5_path)
1450-
os.rmdir(sub21_path)
1451-
1452-
def test_walk_bad_dir(self):
1453-
self.setUpWalk()
1454-
errors = []
1455-
walk_it = self.walk_path.walk(on_error=errors.append)
1456-
root, dirs, files = next(walk_it)
1457-
self.assertEqual(errors, [])
1458-
dir1 = 'SUB1'
1459-
path1 = root / dir1
1460-
path1new = (root / dir1).with_suffix(".new")
1461-
path1.rename(path1new)
1462-
try:
1463-
roots = [r for r, _, _ in walk_it]
1464-
self.assertTrue(errors)
1465-
self.assertNotIn(path1, roots)
1466-
self.assertNotIn(path1new, roots)
1467-
for dir2 in dirs:
1468-
if dir2 != dir1:
1469-
self.assertIn(root / dir2, roots)
1470-
finally:
1471-
path1new.rename(path1)
1472-
1473-
def test_walk_many_open_files(self):
1474-
depth = 30
1475-
base = self.cls(self.base, 'deep')
1476-
path = self.cls(base, *(['d']*depth))
1477-
path.mkdir(parents=True)
1478-
1479-
iters = [base.walk(top_down=False) for _ in range(100)]
1480-
for i in range(depth + 1):
1481-
expected = (path, ['d'] if i else [], [])
1482-
for it in iters:
1483-
self.assertEqual(next(it), expected)
1484-
path = path.parent
1485-
1486-
iters = [base.walk(top_down=True) for _ in range(100)]
1487-
path = base
1488-
for i in range(depth + 1):
1489-
expected = (path, ['d'] if i < depth else [], [])
1490-
for it in iters:
1491-
self.assertEqual(next(it), expected)
1492-
path = path / 'd'
1493-
1494-
def test_walk_above_recursion_limit(self):
1495-
recursion_limit = 40
1496-
# directory_depth > recursion_limit
1497-
directory_depth = recursion_limit + 10
1498-
base = self.cls(self.base, 'deep')
1499-
path = base.joinpath(*(['d'] * directory_depth))
1500-
path.mkdir(parents=True)
1501-
1502-
with infinite_recursion(recursion_limit):
1503-
list(base.walk())
1504-
list(base.walk(top_down=False))
1505-
15061428
def test_glob_empty_pattern(self):
15071429
p = self.cls('')
15081430
with self.assertRaisesRegex(ValueError, 'Unacceptable pattern'):
@@ -1885,6 +1807,84 @@ def test_group_windows(self):
18851807
with self.assertRaises(pathlib.UnsupportedOperation):
18861808
P('c:/').group()
18871809

1810+
def setUpWalk(self):
1811+
super().setUpWalk()
1812+
sub21_path= self.sub2_path / "SUB21"
1813+
tmp5_path = sub21_path / "tmp3"
1814+
broken_link3_path = self.sub2_path / "broken_link3"
1815+
1816+
os.makedirs(sub21_path)
1817+
tmp5_path.write_text("I am tmp5, blame test_pathlib.")
1818+
if self.can_symlink:
1819+
os.symlink(tmp5_path, broken_link3_path)
1820+
self.sub2_tree[2].append('broken_link3')
1821+
self.sub2_tree[2].sort()
1822+
if not is_emscripten:
1823+
# Emscripten fails with inaccessible directories.
1824+
os.chmod(sub21_path, 0)
1825+
try:
1826+
os.listdir(sub21_path)
1827+
except PermissionError:
1828+
self.sub2_tree[1].append('SUB21')
1829+
else:
1830+
os.chmod(sub21_path, stat.S_IRWXU)
1831+
os.unlink(tmp5_path)
1832+
os.rmdir(sub21_path)
1833+
1834+
def test_walk_bad_dir(self):
1835+
self.setUpWalk()
1836+
errors = []
1837+
walk_it = self.walk_path.walk(on_error=errors.append)
1838+
root, dirs, files = next(walk_it)
1839+
self.assertEqual(errors, [])
1840+
dir1 = 'SUB1'
1841+
path1 = root / dir1
1842+
path1new = (root / dir1).with_suffix(".new")
1843+
path1.rename(path1new)
1844+
try:
1845+
roots = [r for r, _, _ in walk_it]
1846+
self.assertTrue(errors)
1847+
self.assertNotIn(path1, roots)
1848+
self.assertNotIn(path1new, roots)
1849+
for dir2 in dirs:
1850+
if dir2 != dir1:
1851+
self.assertIn(root / dir2, roots)
1852+
finally:
1853+
path1new.rename(path1)
1854+
1855+
def test_walk_many_open_files(self):
1856+
depth = 30
1857+
base = self.cls(self.base, 'deep')
1858+
path = self.cls(base, *(['d']*depth))
1859+
path.mkdir(parents=True)
1860+
1861+
iters = [base.walk(top_down=False) for _ in range(100)]
1862+
for i in range(depth + 1):
1863+
expected = (path, ['d'] if i else [], [])
1864+
for it in iters:
1865+
self.assertEqual(next(it), expected)
1866+
path = path.parent
1867+
1868+
iters = [base.walk(top_down=True) for _ in range(100)]
1869+
path = base
1870+
for i in range(depth + 1):
1871+
expected = (path, ['d'] if i < depth else [], [])
1872+
for it in iters:
1873+
self.assertEqual(next(it), expected)
1874+
path = path / 'd'
1875+
1876+
def test_walk_above_recursion_limit(self):
1877+
recursion_limit = 40
1878+
# directory_depth > recursion_limit
1879+
directory_depth = recursion_limit + 10
1880+
base = self.cls(self.base, 'deep')
1881+
path = base.joinpath(*(['d'] * directory_depth))
1882+
path.mkdir(parents=True)
1883+
1884+
with infinite_recursion(recursion_limit):
1885+
list(base.walk())
1886+
list(base.walk(top_down=False))
1887+
18881888

18891889
@unittest.skipIf(os.name == 'nt', 'test requires a POSIX-compatible system')
18901890
class PosixPathTest(PathTest, PurePosixPathTest):

0 commit comments

Comments
 (0)