mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
pathlib tests: create test hierarchy without using class under test (#128200)
In the pathlib tests, avoid using the path class under test (`self.cls`) in test setup. Instead we use `os` functions in `test_pathlib`, and direct manipulation of `DummyPath` internal data in `test_pathlib_abc`.
This commit is contained in:
parent
c5b0c90b62
commit
d61542b5ff
2 changed files with 55 additions and 29 deletions
|
@ -578,10 +578,44 @@ class PathTest(test_pathlib_abc.DummyPathTest, PurePathTest):
|
|||
if name in _tests_needing_symlinks and not self.can_symlink:
|
||||
self.skipTest('requires symlinks')
|
||||
super().setUp()
|
||||
os.chmod(self.parser.join(self.base, 'dirE'), 0)
|
||||
|
||||
def createTestHierarchy(self):
|
||||
os.mkdir(self.base)
|
||||
os.mkdir(os.path.join(self.base, 'dirA'))
|
||||
os.mkdir(os.path.join(self.base, 'dirB'))
|
||||
os.mkdir(os.path.join(self.base, 'dirC'))
|
||||
os.mkdir(os.path.join(self.base, 'dirC', 'dirD'))
|
||||
os.mkdir(os.path.join(self.base, 'dirE'))
|
||||
with open(os.path.join(self.base, 'fileA'), 'wb') as f:
|
||||
f.write(b"this is file A\n")
|
||||
with open(os.path.join(self.base, 'dirB', 'fileB'), 'wb') as f:
|
||||
f.write(b"this is file B\n")
|
||||
with open(os.path.join(self.base, 'dirC', 'fileC'), 'wb') as f:
|
||||
f.write(b"this is file C\n")
|
||||
with open(os.path.join(self.base, 'dirC', 'novel.txt'), 'wb') as f:
|
||||
f.write(b"this is a novel\n")
|
||||
with open(os.path.join(self.base, 'dirC', 'dirD', 'fileD'), 'wb') as f:
|
||||
f.write(b"this is file D\n")
|
||||
os.chmod(os.path.join(self.base, 'dirE'), 0)
|
||||
if self.can_symlink:
|
||||
# Relative symlinks.
|
||||
os.symlink('fileA', os.path.join(self.base, 'linkA'))
|
||||
os.symlink('non-existing', os.path.join(self.base, 'brokenLink'))
|
||||
os.symlink('dirB',
|
||||
os.path.join(self.base, 'linkB'),
|
||||
target_is_directory=True)
|
||||
os.symlink(os.path.join('..', 'dirB'),
|
||||
os.path.join(self.base, 'dirA', 'linkC'),
|
||||
target_is_directory=True)
|
||||
# This one goes upwards, creating a loop.
|
||||
os.symlink(os.path.join('..', 'dirB'),
|
||||
os.path.join(self.base, 'dirB', 'linkD'),
|
||||
target_is_directory=True)
|
||||
# Broken symlink (pointing to itself).
|
||||
os.symlink('brokenLinkLoop', os.path.join(self.base, 'brokenLinkLoop'))
|
||||
|
||||
def tearDown(self):
|
||||
os.chmod(self.parser.join(self.base, 'dirE'), 0o777)
|
||||
os.chmod(os.path.join(self.base, 'dirE'), 0o777)
|
||||
os_helper.rmtree(self.base)
|
||||
|
||||
def tempdir(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue