[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:
parent
987ae8e943
commit
4feb8d6c01
|
@ -45,22 +45,21 @@ class Linker(object):
|
||||||
def relpath(p1, p2, sep='/', back='..', normalize=True):
|
def relpath(p1, p2, sep='/', back='..', normalize=True):
|
||||||
""" create a relative path from p1 to p2
|
""" create a relative path from p1 to p2
|
||||||
|
|
||||||
sep is the seperator used, set to '\\' on windows (but only
|
sep is the seperator used for input and (depending
|
||||||
when not using 'normalize'! see below)
|
on the setting of 'normalize', see below) output
|
||||||
|
|
||||||
back is the string used to indicate the parent directory
|
back is the string used to indicate the parent directory
|
||||||
|
|
||||||
when 'normalize' is True, any backslashes (\) in the path
|
when 'normalize' is True, any backslashes (\) in the path
|
||||||
will be replaced with forward slashes, resulting in a consistent
|
will be replaced with forward slashes, resulting in a consistent
|
||||||
output on Windows and the rest of the world (this happens before
|
output on Windows and the rest of the world
|
||||||
the 'sep' argument is used, and therefore renders that useless!)
|
|
||||||
|
|
||||||
paths to directories must end on a / (URL style)
|
paths to directories must end on a / (URL style)
|
||||||
"""
|
"""
|
||||||
if normalize:
|
if normalize:
|
||||||
|
p1 = p1.replace(sep, '/')
|
||||||
|
p2 = p2.replace(sep, '/')
|
||||||
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
|
# XXX would be cool to be able to do long filename expansion and drive
|
||||||
# letter fixes here, and such... iow: windows sucks :(
|
# letter fixes here, and such... iow: windows sucks :(
|
||||||
if (p1.startswith(sep) ^ p2.startswith(sep)):
|
if (p1.startswith(sep) ^ p2.startswith(sep)):
|
||||||
|
|
|
@ -18,25 +18,25 @@ class TestLinker(object):
|
||||||
assert relpath == 'path/local.html'
|
assert relpath == 'path/local.html'
|
||||||
|
|
||||||
testspec = [
|
testspec = [
|
||||||
'a a/b a/b',
|
'a a/b a/b /',
|
||||||
'/a /a/b a/b',
|
'/a /a/b a/b /',
|
||||||
'a b b',
|
'a b b /',
|
||||||
'/a /b b',
|
'/a /b b /',
|
||||||
'a/b c/d ../c/d',
|
'a/b c/d ../c/d /',
|
||||||
'/a/b /c/d ../c/d',
|
'/a/b /c/d ../c/d /',
|
||||||
'a/b a ../a',
|
'a/b a ../a /',
|
||||||
'/a/b /a ../a',
|
'/a/b /a ../a /',
|
||||||
'c:\\foo\\bar c:\\foo ../foo',
|
'c:\\foo\\bar c:\\foo ../foo \\',
|
||||||
]
|
]
|
||||||
|
|
||||||
def gen_check(frompath, topath, expected):
|
def gen_check(frompath, topath, sep, expected):
|
||||||
result = relpath(frompath, topath)
|
result = relpath(frompath, topath, sep=sep)
|
||||||
assert result == expected
|
assert result == expected
|
||||||
|
|
||||||
def test_gen_check():
|
def test_gen_check():
|
||||||
for line in testspec:
|
for line in testspec:
|
||||||
frompath, topath, expected = line.split()
|
frompath, topath, expected, sep = line.split()
|
||||||
yield gen_check, frompath, topath, expected,
|
yield gen_check, frompath, topath, sep, expected
|
||||||
|
|
||||||
def test_check_incompatible():
|
def test_check_incompatible():
|
||||||
py.test.raises(ValueError, "relpath('/a', 'b')")
|
py.test.raises(ValueError, "relpath('/a', 'b')")
|
||||||
|
|
Loading…
Reference in New Issue