Skip to content

Commit e212618

Browse files
authored
GH-89812: Simplify creation of symlinks in pathlib tests. (GH-106061)
Remove `PathTest.dirlink()` function. Symlinks in `PathTest.setUp()` are created using `os.symlink()` directly; symlinks in test functions use `Path.symlink_to()` in order to make the tests applicable to a (near-)future `AbstractPath` class.
1 parent 46c1097 commit e212618

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

Lib/test/test_pathlib.py

+12-20
Original file line numberDiff line numberDiff line change
@@ -1620,21 +1620,13 @@ def cleanup():
16201620
# Relative symlinks.
16211621
os.symlink('fileA', join('linkA'))
16221622
os.symlink('non-existing', join('brokenLink'))
1623-
self.dirlink('dirB', join('linkB'))
1624-
self.dirlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'))
1623+
os.symlink('dirB', join('linkB'), target_is_directory=True)
1624+
os.symlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'), target_is_directory=True)
16251625
# This one goes upwards, creating a loop.
1626-
self.dirlink(os.path.join('..', 'dirB'), join('dirB', 'linkD'))
1626+
os.symlink(os.path.join('..', 'dirB'), join('dirB', 'linkD'), target_is_directory=True)
16271627
# Broken symlink (pointing to itself).
16281628
os.symlink('brokenLinkLoop', join('brokenLinkLoop'))
16291629

1630-
if os.name == 'nt':
1631-
# Workaround for http://bugs.python.org/issue13772.
1632-
def dirlink(self, src, dest):
1633-
os.symlink(src, dest, target_is_directory=True)
1634-
else:
1635-
def dirlink(self, src, dest):
1636-
os.symlink(src, dest)
1637-
16381630
def assertSame(self, path_a, path_b):
16391631
self.assertTrue(os.path.samefile(str(path_a), str(path_b)),
16401632
"%r and %r don't point to the same file" %
@@ -2118,8 +2110,8 @@ def test_resolve_common(self):
21182110
d = os_helper._longpath(tempfile.mkdtemp(suffix='-dirD',
21192111
dir=os.getcwd()))
21202112
self.addCleanup(os_helper.rmtree, d)
2121-
os.symlink(os.path.join(d), join('dirA', 'linkX'))
2122-
os.symlink(join('dirB'), os.path.join(d, 'linkY'))
2113+
P(BASE, 'dirA', 'linkX').symlink_to(d)
2114+
P(BASE, str(d), 'linkY').symlink_to(join('dirB'))
21232115
p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB')
21242116
self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))
21252117
# Non-strict
@@ -2140,9 +2132,9 @@ def test_resolve_common(self):
21402132
def test_resolve_dot(self):
21412133
# See http://web.archive.org/web/20200623062557/https://bitbucket.org/pitrou/pathlib/issues/9/
21422134
p = self.cls(BASE)
2143-
self.dirlink('.', join('0'))
2144-
self.dirlink(os.path.join('0', '0'), join('1'))
2145-
self.dirlink(os.path.join('1', '1'), join('2'))
2135+
p.joinpath('0').symlink_to('.', target_is_directory=True)
2136+
p.joinpath('1').symlink_to(os.path.join('0', '0'), target_is_directory=True)
2137+
p.joinpath('2').symlink_to(os.path.join('1', '1'), target_is_directory=True)
21462138
q = p / '2'
21472139
self.assertEqual(q.resolve(strict=True), p)
21482140
r = q / '3' / '4'
@@ -2320,10 +2312,10 @@ def test_parts_interning(self):
23202312
def _check_complex_symlinks(self, link0_target):
23212313
# Test solving a non-looping chain of symlinks (issue #19887).
23222314
P = self.cls(BASE)
2323-
self.dirlink(os.path.join('link0', 'link0'), join('link1'))
2324-
self.dirlink(os.path.join('link1', 'link1'), join('link2'))
2325-
self.dirlink(os.path.join('link2', 'link2'), join('link3'))
2326-
self.dirlink(link0_target, join('link0'))
2315+
P.joinpath('link1').symlink_to(os.path.join('link0', 'link0'), target_is_directory=True)
2316+
P.joinpath('link2').symlink_to(os.path.join('link1', 'link1'), target_is_directory=True)
2317+
P.joinpath('link3').symlink_to(os.path.join('link2', 'link2'), target_is_directory=True)
2318+
P.joinpath('link0').symlink_to(link0_target, target_is_directory=True)
23272319

23282320
# Resolve absolute paths.
23292321
p = (P / 'link0').resolve()

0 commit comments

Comments
 (0)