path_abs = abspath(normpath(path))
start_drive, start_rest = splitdrive(start_abs)
path_drive, path_rest = splitdrive(path_abs)
- if start_drive != path_drive:
+ if normcase(start_drive) != normcase(path_drive):
error = "path is on mount '{0}', start on mount '{1}'".format(
path_drive, start_drive)
raise ValueError(error)
# Work out how much of the filepath is shared by start and path.
i = 0
for e1, e2 in zip(start_list, path_list):
- if e1 != e2:
+ if normcase(e1) != normcase(e2):
break
i += 1
"../"+curdir+"/a/b")
self.assertEqual(posixpath.relpath("a", "b/c"), "../../a")
self.assertEqual(posixpath.relpath("a", "a"), ".")
+ self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x/y/z"), '../../../foo/bar/bat')
+ self.assertEqual(posixpath.relpath("/foo/bar/bat", "/foo/bar"), 'bat')
+ self.assertEqual(posixpath.relpath("/foo/bar/bat", "/"), 'foo/bar/bat')
+ self.assertEqual(posixpath.relpath("/", "/foo/bar/bat"), '../../..')
+ self.assertEqual(posixpath.relpath("/foo/bar/bat", "/x"), '../foo/bar/bat')
+ self.assertEqual(posixpath.relpath("/x", "/foo/bar/bat"), '../../../x')
+ self.assertEqual(posixpath.relpath("/", "/"), '.')
+ self.assertEqual(posixpath.relpath("/a", "/a"), '.')
+ self.assertEqual(posixpath.relpath("/a/b", "/a/b"), '.')
finally:
os.getcwd = real_getcwd
b"../"+curdir+b"/a/b")
self.assertEqual(posixpath.relpath(b"a", b"b/c"), b"../../a")
self.assertEqual(posixpath.relpath(b"a", b"a"), b".")
+ self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x/y/z"), b'../../../foo/bar/bat')
+ self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/foo/bar"), b'bat')
+ self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/"), b'foo/bar/bat')
+ self.assertEqual(posixpath.relpath(b"/", b"/foo/bar/bat"), b'../../..')
+ self.assertEqual(posixpath.relpath(b"/foo/bar/bat", b"/x"), b'../foo/bar/bat')
+ self.assertEqual(posixpath.relpath(b"/x", b"/foo/bar/bat"), b'../../../x')
+ self.assertEqual(posixpath.relpath(b"/", b"/"), b'.')
+ self.assertEqual(posixpath.relpath(b"/a", b"/a"), b'.')
+ self.assertEqual(posixpath.relpath(b"/a/b", b"/a/b"), b'.')
self.assertRaises(TypeError, posixpath.relpath, b"bytes", "str")
self.assertRaises(TypeError, posixpath.relpath, "str", b"bytes")