refine bestrelpath to return "." for X.bestrelpath(X) and refine its docstring

--HG--
branch : trunk
This commit is contained in:
holger krekel 2010-06-28 16:32:43 +02:00
parent 2f50ed3e99
commit b8db15a94f
3 changed files with 10 additions and 3 deletions

View File

@ -53,6 +53,8 @@ Bug fixes / Maintenance
on all python versions
- install plain py.test/py.which scripts also for Jython, this helps to
get canonical script paths in virtualenv situations
- make path.bestrelpath(path) return ".", note that when calling
X.bestrelpath the assumption is that X is a directory.
Changes between 1.3.0 and 1.3.1
==================================================

View File

@ -194,10 +194,13 @@ newline will be removed from the end of each line. """
def bestrelpath(self, dest):
""" return a string which is a relative path from self
to dest such that self.join(bestrelpath) == dest and
if not such path can be determined return dest.
(assumed to be a directory) to dest such that
self.join(bestrelpath) == dest and if not such
path can be determined return dest.
"""
try:
if self == dest:
return os.curdir
base = self.common(dest)
if not base: # can be the case on windows
return str(dest)
@ -207,7 +210,7 @@ newline will be removed from the end of each line. """
n = self2base.count(self.sep) + 1
else:
n = 0
l = ['..'] * n
l = [os.pardir] * n
if reldest:
l.append(reldest)
target = dest.sep.join(l)

View File

@ -117,6 +117,8 @@ class CommonFSTests(object):
def test_bestrelpath(self, path1):
curdir = path1
sep = curdir.sep
s = curdir.bestrelpath(curdir)
assert s == "."
s = curdir.bestrelpath(curdir.join("hello", "world"))
assert s == "hello" + sep + "world"