[svn r37328] Fixed problem with Windows paths in tests when running on Linux (and fixed

relpath() api to deal with line seps in a better way).

--HG--
branch : trunk
This commit is contained in:
guido 2007-01-25 14:22:04 +01:00
parent 987ae8e943
commit 4feb8d6c01
2 changed files with 18 additions and 19 deletions

View File

@ -45,22 +45,21 @@ class Linker(object):
def relpath(p1, p2, sep='/', back='..', normalize=True):
""" create a relative path from p1 to p2
sep is the seperator used, set to '\\' on windows (but only
when not using 'normalize'! see below)
sep is the seperator used for input and (depending
on the setting of 'normalize', see below) output
back is the string used to indicate the parent directory
when 'normalize' is True, any backslashes (\) in the path
will be replaced with forward slashes, resulting in a consistent
output on Windows and the rest of the world (this happens before
the 'sep' argument is used, and therefore renders that useless!)
output on Windows and the rest of the world
paths to directories must end on a / (URL style)
"""
if normalize:
p1 = p1.replace(sep, '/')
p2 = p2.replace(sep, '/')
sep = '/'
p1 = p1.replace(os.path.sep, '/')
p2 = p2.replace(os.path.sep, '/')
# XXX would be cool to be able to do long filename expansion and drive
# letter fixes here, and such... iow: windows sucks :(
if (p1.startswith(sep) ^ p2.startswith(sep)):

View File

@ -18,25 +18,25 @@ class TestLinker(object):
assert relpath == 'path/local.html'
testspec = [
'a a/b a/b',
'/a /a/b a/b',
'a b b',
'/a /b b',
'a/b c/d ../c/d',
'/a/b /c/d ../c/d',
'a/b a ../a',
'/a/b /a ../a',
'c:\\foo\\bar c:\\foo ../foo',
'a a/b a/b /',
'/a /a/b a/b /',
'a b b /',
'/a /b b /',
'a/b c/d ../c/d /',
'/a/b /c/d ../c/d /',
'a/b a ../a /',
'/a/b /a ../a /',
'c:\\foo\\bar c:\\foo ../foo \\',
]
def gen_check(frompath, topath, expected):
result = relpath(frompath, topath)
def gen_check(frompath, topath, sep, expected):
result = relpath(frompath, topath, sep=sep)
assert result == expected
def test_gen_check():
for line in testspec:
frompath, topath, expected = line.split()
yield gen_check, frompath, topath, expected,
frompath, topath, expected, sep = line.split()
yield gen_check, frompath, topath, sep, expected
def test_check_incompatible():
py.test.raises(ValueError, "relpath('/a', 'b')")