mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
#1742: don't raise exception on os.path.relpath("a", "a"), but return os.curdir.
Reported by Jesse Towner.
This commit is contained in:
parent
e2a902c669
commit
183a084da3
5 changed files with 9 additions and 0 deletions
|
@ -490,4 +490,6 @@ def relpath(path, start=curdir):
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||||
|
if not rel_list:
|
||||||
|
return curdir
|
||||||
return join(*rel_list)
|
return join(*rel_list)
|
||||||
|
|
|
@ -398,4 +398,6 @@ def relpath(path, start=curdir):
|
||||||
i = len(commonprefix([start_list, path_list]))
|
i = len(commonprefix([start_list, path_list]))
|
||||||
|
|
||||||
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
|
||||||
|
if not rel_list:
|
||||||
|
return curdir
|
||||||
return join(*rel_list)
|
return join(*rel_list)
|
||||||
|
|
|
@ -166,6 +166,7 @@ tester('ntpath.relpath("a", "../b")', '..\\'+currentdir+'\\a')
|
||||||
tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
|
tester('ntpath.relpath("a/b", "../c")', '..\\'+currentdir+'\\a\\b')
|
||||||
tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
|
tester('ntpath.relpath("a", "b/c")', '..\\..\\a')
|
||||||
tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
|
tester('ntpath.relpath("//conky/mountpoint/a", "//conky/mountpoint/b/c")', '..\\..\\a')
|
||||||
|
tester('ntpath.relpath("a", "a")', '.')
|
||||||
|
|
||||||
if errors:
|
if errors:
|
||||||
raise TestFailed(str(errors) + " errors.")
|
raise TestFailed(str(errors) + " errors.")
|
||||||
|
|
|
@ -501,6 +501,7 @@ class PosixPathTest(unittest.TestCase):
|
||||||
self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
|
self.assertEqual(posixpath.relpath("a", "../b"), "../"+curdir+"/a")
|
||||||
self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
|
self.assertEqual(posixpath.relpath("a/b", "../c"), "../"+curdir+"/a/b")
|
||||||
self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
|
self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
|
||||||
|
self.assertEqual(posixpath.relpath("a", "a"), ".")
|
||||||
finally:
|
finally:
|
||||||
os.getcwd = real_getcwd
|
os.getcwd = real_getcwd
|
||||||
|
|
||||||
|
|
|
@ -342,6 +342,9 @@ Core and builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Bug #1742: return os.curdir from os.path.relpath() if both arguments are
|
||||||
|
equal instead of raising an exception.
|
||||||
|
|
||||||
- Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
|
- Patch #1637: fix urlparse for URLs like 'http://x.com?arg=/foo'.
|
||||||
|
|
||||||
- Patch #1698: allow '@' in username parsed by urlparse.py.
|
- Patch #1698: allow '@' in username parsed by urlparse.py.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue