mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." (GH-107014) (#107315)
gh-105002: [pathlib] Fix relative_to with walk_up=True using ".." (GH-107014)
It makes sense to raise an Error because ".." can not
be resolved and the current working directory is unknown.
(cherry picked from commit e7e6e4b035
)
Co-authored-by: János Kukovecz <kukoveczjanos@gmail.com>
This commit is contained in:
parent
58af565c50
commit
4f6d7a5890
3 changed files with 19 additions and 2 deletions
|
@ -626,8 +626,14 @@ class _BasePurePathTest(object):
|
|||
self.assertRaises(ValueError, p.relative_to, P('a/b/c'))
|
||||
self.assertRaises(ValueError, p.relative_to, P('a/c'))
|
||||
self.assertRaises(ValueError, p.relative_to, P('/a'))
|
||||
self.assertRaises(ValueError, p.relative_to, P("../a"))
|
||||
self.assertRaises(ValueError, p.relative_to, P("a/.."))
|
||||
self.assertRaises(ValueError, p.relative_to, P("/a/.."))
|
||||
self.assertRaises(ValueError, p.relative_to, P('/'), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P('/a'), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("../a"), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("a/.."), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("/a/.."), walk_up=True)
|
||||
p = P('/a/b')
|
||||
self.assertEqual(p.relative_to(P('/')), P('a/b'))
|
||||
self.assertEqual(p.relative_to('/'), P('a/b'))
|
||||
|
@ -656,8 +662,14 @@ class _BasePurePathTest(object):
|
|||
self.assertRaises(ValueError, p.relative_to, P())
|
||||
self.assertRaises(ValueError, p.relative_to, '')
|
||||
self.assertRaises(ValueError, p.relative_to, P('a'))
|
||||
self.assertRaises(ValueError, p.relative_to, P("../a"))
|
||||
self.assertRaises(ValueError, p.relative_to, P("a/.."))
|
||||
self.assertRaises(ValueError, p.relative_to, P("/a/.."))
|
||||
self.assertRaises(ValueError, p.relative_to, P(''), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P('a'), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("../a"), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("a/.."), walk_up=True)
|
||||
self.assertRaises(ValueError, p.relative_to, P("/a/.."), walk_up=True)
|
||||
|
||||
def test_is_relative_to_common(self):
|
||||
P = self.cls
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue