[svn r37325] Fixed problems with windows path seperators, fixed functional test exec command for win32
--HG-- branch : trunk
This commit is contained in:
parent
ba07a8769f
commit
eac3021405
|
@ -1,4 +1,5 @@
|
||||||
import py
|
import py
|
||||||
|
import os
|
||||||
import inspect
|
import inspect
|
||||||
from py.__.apigen.layout import LayoutPage
|
from py.__.apigen.layout import LayoutPage
|
||||||
from py.__.apigen.source import browser as source_browser
|
from py.__.apigen.source import browser as source_browser
|
||||||
|
@ -167,11 +168,11 @@ class SourcePageBuilder(AbstractPageBuilder):
|
||||||
def build_navigation(self, fspath):
|
def build_navigation(self, fspath):
|
||||||
nav = H.Navigation()
|
nav = H.Navigation()
|
||||||
relpath = fspath.relto(self.projroot)
|
relpath = fspath.relto(self.projroot)
|
||||||
path = relpath.split('/')
|
path = relpath.split(os.path.sep)
|
||||||
indent = 0
|
indent = 0
|
||||||
# build links to parents
|
# build links to parents
|
||||||
for i in xrange(len(path)):
|
for i in xrange(len(path)):
|
||||||
dirpath = '/'.join(path[:i])
|
dirpath = os.path.sep.join(path[:i])
|
||||||
abspath = self.projroot.join(dirpath).strpath
|
abspath = self.projroot.join(dirpath).strpath
|
||||||
if i == 0:
|
if i == 0:
|
||||||
text = 'root'
|
text = 'root'
|
||||||
|
@ -244,15 +245,17 @@ class SourcePageBuilder(AbstractPageBuilder):
|
||||||
if fspath.ext in ['.pyc', '.pyo']:
|
if fspath.ext in ['.pyc', '.pyo']:
|
||||||
continue
|
continue
|
||||||
relfspath = fspath.relto(base)
|
relfspath = fspath.relto(base)
|
||||||
if relfspath.find('/.') > -1:
|
if relfspath.find('%s.' % (os.path.sep,)) > -1:
|
||||||
# skip hidden dirs and files
|
# skip hidden dirs and files
|
||||||
continue
|
continue
|
||||||
elif fspath.check(dir=True):
|
elif fspath.check(dir=True):
|
||||||
if relfspath != '':
|
if relfspath != '':
|
||||||
relfspath += '/'
|
relfspath += os.path.sep
|
||||||
reloutputpath = 'source/%sindex.html' % (relfspath,)
|
reloutputpath = 'source%s%sindex.html' % (os.path.sep,
|
||||||
|
relfspath)
|
||||||
else:
|
else:
|
||||||
reloutputpath = "source/%s.html" % (relfspath,)
|
reloutputpath = "source%s%s.html" % (os.path.sep, relfspath)
|
||||||
|
reloutputpath = reloutputpath.replace(os.path.sep, '/')
|
||||||
outputpath = self.base.join(reloutputpath)
|
outputpath = self.base.join(reloutputpath)
|
||||||
self.linker.set_link(str(fspath), reloutputpath)
|
self.linker.set_link(str(fspath), reloutputpath)
|
||||||
passed.append((fspath, outputpath))
|
passed.append((fspath, outputpath))
|
||||||
|
@ -279,7 +282,7 @@ class SourcePageBuilder(AbstractPageBuilder):
|
||||||
else:
|
else:
|
||||||
tag, nav = self.build_nonpython_page(fspath)
|
tag, nav = self.build_nonpython_page(fspath)
|
||||||
title = 'sources for %s' % (fspath.basename,)
|
title = 'sources for %s' % (fspath.basename,)
|
||||||
reltargetpath = outputpath.relto(self.base)
|
reltargetpath = outputpath.relto(self.base).replace(os.path.sep, '/')
|
||||||
self.write_page(title, reltargetpath, project, tag, nav)
|
self.write_page(title, reltargetpath, project, tag, nav)
|
||||||
|
|
||||||
class ApiPageBuilder(AbstractPageBuilder):
|
class ApiPageBuilder(AbstractPageBuilder):
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import py
|
import py
|
||||||
|
import os
|
||||||
html = py.xml.html
|
html = py.xml.html
|
||||||
|
|
||||||
def getrelfspath(dotted_name):
|
def getrelfspath(dotted_name):
|
||||||
|
@ -41,7 +42,27 @@ class Linker(object):
|
||||||
finally:
|
finally:
|
||||||
del self.fromlocation
|
del self.fromlocation
|
||||||
|
|
||||||
def relpath(p1, p2, sep='/', back='..'):
|
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)
|
||||||
|
|
||||||
|
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!)
|
||||||
|
|
||||||
|
paths to directories must end on a / (URL style)
|
||||||
|
"""
|
||||||
|
if normalize:
|
||||||
|
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)):
|
if (p1.startswith(sep) ^ p2.startswith(sep)):
|
||||||
raise ValueError("mixed absolute relative path: %r -> %r" %(p1, p2))
|
raise ValueError("mixed absolute relative path: %r -> %r" %(p1, p2))
|
||||||
fromlist = p1.split(sep)
|
fromlist = p1.split(sep)
|
||||||
|
|
|
@ -75,10 +75,14 @@ def test_apigen_functional():
|
||||||
tempdir = py.test.ensuretemp('test_apigen_functional_results')
|
tempdir = py.test.ensuretemp('test_apigen_functional_results')
|
||||||
pydir = py.magic.autopath().dirpath().dirpath().dirpath()
|
pydir = py.magic.autopath().dirpath().dirpath().dirpath()
|
||||||
pkgdir = fs_root.join('pkg')
|
pkgdir = fs_root.join('pkg')
|
||||||
|
if py.std.sys.platform == 'win32':
|
||||||
|
cmd = 'set APIGEN_TARGET=%s && python "%s/bin/py.test"' % (tempdir,
|
||||||
|
pydir)
|
||||||
|
else:
|
||||||
|
cmd = 'APIGEN_TARGET="%s" "%s/bin/py.test"' % (tempdir, pydir)
|
||||||
try:
|
try:
|
||||||
output = py.process.cmdexec('APIGEN_TARGET="%s" %s/bin/py.test '
|
output = py.process.cmdexec('%s --apigen="%s/apigen.py" "%s"' % (
|
||||||
'--apigen="%s/apigen.py" "%s"' % (
|
cmd, pydir.join('apigen'),
|
||||||
tempdir, pydir, pydir.join('apigen'),
|
|
||||||
pkgdir))
|
pkgdir))
|
||||||
except py.error.Error, e:
|
except py.error.Error, e:
|
||||||
print e.out
|
print e.out
|
||||||
|
|
|
@ -17,8 +17,6 @@ class TestLinker(object):
|
||||||
linker.get_target, 'py.path.local')
|
linker.get_target, 'py.path.local')
|
||||||
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',
|
||||||
|
@ -28,17 +26,17 @@ testspec = [
|
||||||
'/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',
|
||||||
|
]
|
||||||
|
|
||||||
def gen_check(frompath, topath, expected):
|
def gen_check(frompath, topath, expected):
|
||||||
result = relpath(frompath, topath)
|
result = relpath(frompath, topath)
|
||||||
print "linking", frompath, "to", topath
|
|
||||||
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 = line.split()
|
||||||
yield gen_check, frompath, topath, expected
|
yield gen_check, frompath, topath, 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