Skip to content

Commit 51af82c

Browse files
committed
Add a test for complex symlinks.
1 parent 6e8bc50 commit 51af82c

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

Lib/test/test_pathlib.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,20 +1093,21 @@ def setUp(self):
10931093
with open(join('dirC', 'dirD', 'fileD'), 'wb') as f:
10941094
f.write(b"this is file D\n")
10951095
if not symlink_skip_reason:
1096-
if os.name == 'nt':
1097-
# Workaround for http://bugs.python.org/issue13772
1098-
def dirlink(src, dest):
1099-
os.symlink(src, dest, target_is_directory=True)
1100-
else:
1101-
def dirlink(src, dest):
1102-
os.symlink(src, dest)
11031096
# Relative symlinks
11041097
os.symlink('fileA', join('linkA'))
11051098
os.symlink('non-existing', join('brokenLink'))
1106-
dirlink('dirB', join('linkB'))
1107-
dirlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'))
1099+
self.dirlink('dirB', join('linkB'))
1100+
self.dirlink(os.path.join('..', 'dirB'), join('dirA', 'linkC'))
11081101
# This one goes upwards but doesn't create a loop
1109-
dirlink(os.path.join('..', 'dirB'), join('dirB', 'linkD'))
1102+
self.dirlink(os.path.join('..', 'dirB'), join('dirB', 'linkD'))
1103+
1104+
if os.name == 'nt':
1105+
# Workaround for http://bugs.python.org/issue13772
1106+
def dirlink(self, src, dest):
1107+
os.symlink(src, dest, target_is_directory=True)
1108+
else:
1109+
def dirlink(self, src, dest):
1110+
os.symlink(src, dest)
11101111

11111112
def assertSame(self, path_a, path_b):
11121113
self.assertTrue(os.path.samefile(str(path_a), str(path_b)),
@@ -1269,6 +1270,16 @@ def test_resolve_common(self):
12691270
p = P(BASE, 'dirA', 'linkX', 'linkY', 'fileB')
12701271
self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))
12711272

1273+
@with_symlinks
1274+
def test_resolve_dot(self):
1275+
# See https://bitbucket.org/pitrou/pathlib/issue/9/pathresolve-fails-on-complex-symlinks
1276+
p = self.cls(BASE)
1277+
self.dirlink('.', join('0'))
1278+
self.dirlink('0/0', join('1'))
1279+
self.dirlink('1/1', join('2'))
1280+
q = p / '2'
1281+
self.assertEqual(q.resolve(), p)
1282+
12721283
def test_with(self):
12731284
p = self.cls(BASE)
12741285
it = p.iterdir()

0 commit comments

Comments
 (0)