bpo-30177: pathlib: include the full path in resolve(strict=False) (#… · python/cpython@ceabf9a · GitHub
Skip to content

Commit ceabf9a

Browse files
seirlzooba
authored andcommitted
bpo-30177: pathlib: include the full path in resolve(strict=False) (#1893) (#1985)
1 parent 09b6c0c commit ceabf9a

3 files changed

Lines changed: 21 additions & 20 deletions

File tree

Lib/pathlib.py

Lines changed: 8 additions & 11 deletions

Lib/test/test_pathlib.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,10 +1507,10 @@ def test_resolve_common(self):
15071507
os.path.join(BASE, 'foo'))
15081508
p = P(BASE, 'foo', 'in', 'spam')
15091509
self.assertEqual(str(p.resolve(strict=False)),
1510-
os.path.join(BASE, 'foo'))
1510+
os.path.join(BASE, 'foo', 'in', 'spam'))
15111511
p = P(BASE, '..', 'foo', 'in', 'spam')
15121512
self.assertEqual(str(p.resolve(strict=False)),
1513-
os.path.abspath(os.path.join('foo')))
1513+
os.path.abspath(os.path.join('foo', 'in', 'spam')))
15141514
# These are all relative symlinks
15151515
p = P(BASE, 'dirB', 'fileB')
15161516
self._check_resolve_relative(p, p)
@@ -1522,16 +1522,18 @@ def test_resolve_common(self):
15221522
self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB'))
15231523
# Non-strict
15241524
p = P(BASE, 'dirA', 'linkC', 'fileB', 'foo', 'in', 'spam')
1525-
self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB', 'foo'), False)
1525+
self._check_resolve_relative(p, P(BASE, 'dirB', 'fileB', 'foo', 'in',
1526+
'spam'), False)
15261527
p = P(BASE, 'dirA', 'linkC', '..', 'foo', 'in', 'spam')
15271528
if os.name == 'nt':
15281529
# In Windows, if linkY points to dirB, 'dirA\linkY\..'
15291530
# resolves to 'dirA' without resolving linkY first.
1530-
self._check_resolve_relative(p, P(BASE, 'dirA', 'foo'), False)
1531+
self._check_resolve_relative(p, P(BASE, 'dirA', 'foo', 'in',
1532+
'spam'), False)
15311533
else:
15321534
# In Posix, if linkY points to dirB, 'dirA/linkY/..'
15331535
# resolves to 'dirB/..' first before resolving to parent of dirB.
1534-
self._check_resolve_relative(p, P(BASE, 'foo'), False)
1536+
self._check_resolve_relative(p, P(BASE, 'foo', 'in', 'spam'), False)
15351537
# Now create absolute symlinks
15361538
d = tempfile.mkdtemp(suffix='-dirD')
15371539
self.addCleanup(support.rmtree, d)
@@ -1541,16 +1543,17 @@ def test_resolve_common(self):
15411543
self._check_resolve_absolute(p, P(BASE, 'dirB', 'fileB'))
15421544
# Non-strict
15431545
p = P(BASE, 'dirA', 'linkX', 'linkY', 'foo', 'in', 'spam')
1544-
self._check_resolve_relative(p, P(BASE, 'dirB', 'foo'), False)
1546+
self._check_resolve_relative(p, P(BASE, 'dirB', 'foo', 'in', 'spam'),
1547+
False)
15451548
p = P(BASE, 'dirA', 'linkX', 'linkY', '..', 'foo', 'in', 'spam')
15461549
if os.name == 'nt':
15471550
# In Windows, if linkY points to dirB, 'dirA\linkY\..'
15481551
# resolves to 'dirA' without resolving linkY first.
1549-
self._check_resolve_relative(p, P(d, 'foo'), False)
1552+
self._check_resolve_relative(p, P(d, 'foo', 'in', 'spam'), False)
15501553
else:
15511554
# In Posix, if linkY points to dirB, 'dirA/linkY/..'
15521555
# resolves to 'dirB/..' first before resolving to parent of dirB.
1553-
self._check_resolve_relative(p, P(BASE, 'foo'), False)
1556+
self._check_resolve_relative(p, P(BASE, 'foo', 'in', 'spam'), False)
15541557

15551558
@with_symlinks
15561559
def test_resolve_dot(self):
@@ -1564,7 +1567,7 @@ def test_resolve_dot(self):
15641567
r = q / '3' / '4'
15651568
self.assertRaises(FileNotFoundError, r.resolve, strict=True)
15661569
# Non-strict
1567-
self.assertEqual(r.resolve(strict=False), p / '3')
1570+
self.assertEqual(r.resolve(strict=False), p / '3' / '4')
15681571

15691572
def test_with(self):
15701573
p = self.cls(BASE)

Misc/ACKS

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)