[svn r37325] Fixed problems with windows path seperators, fixed functional test exec command for win32

--HG--
branch : trunk
This commit is contained in:
guido 2007-01-25 13:54:51 +01:00
parent ba07a8769f
commit eac3021405
4 changed files with 42 additions and 16 deletions

View File

@ -1,4 +1,5 @@
import py
import os
import inspect
from py.__.apigen.layout import LayoutPage
from py.__.apigen.source import browser as source_browser
@ -167,11 +168,11 @@ class SourcePageBuilder(AbstractPageBuilder):
def build_navigation(self, fspath):
nav = H.Navigation()
relpath = fspath.relto(self.projroot)
path = relpath.split('/')
path = relpath.split(os.path.sep)
indent = 0
# build links to parents
for i in xrange(len(path)):
dirpath = '/'.join(path[:i])
dirpath = os.path.sep.join(path[:i])
abspath = self.projroot.join(dirpath).strpath
if i == 0:
text = 'root'
@ -244,15 +245,17 @@ class SourcePageBuilder(AbstractPageBuilder):
if fspath.ext in ['.pyc', '.pyo']:
continue
relfspath = fspath.relto(base)
if relfspath.find('/.') > -1:
if relfspath.find('%s.' % (os.path.sep,)) > -1:
# skip hidden dirs and files
continue
elif fspath.check(dir=True):
if relfspath != '':
relfspath += '/'
reloutputpath = 'source/%sindex.html' % (relfspath,)
relfspath += os.path.sep
reloutputpath = 'source%s%sindex.html' % (os.path.sep,
relfspath)
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)
self.linker.set_link(str(fspath), reloutputpath)
passed.append((fspath, outputpath))
@ -279,7 +282,7 @@ class SourcePageBuilder(AbstractPageBuilder):
else:
tag, nav = self.build_nonpython_page(fspath)
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)
class ApiPageBuilder(AbstractPageBuilder):

View File

@ -1,4 +1,5 @@
import py
import os
html = py.xml.html
def getrelfspath(dotted_name):
@ -41,7 +42,27 @@ class Linker(object):
finally:
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)):
raise ValueError("mixed absolute relative path: %r -> %r" %(p1, p2))
fromlist = p1.split(sep)

View File

@ -75,10 +75,14 @@ def test_apigen_functional():
tempdir = py.test.ensuretemp('test_apigen_functional_results')
pydir = py.magic.autopath().dirpath().dirpath().dirpath()
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:
output = py.process.cmdexec('APIGEN_TARGET="%s" %s/bin/py.test '
'--apigen="%s/apigen.py" "%s"' % (
tempdir, pydir, pydir.join('apigen'),
output = py.process.cmdexec('%s --apigen="%s/apigen.py" "%s"' % (
cmd, pydir.join('apigen'),
pkgdir))
except py.error.Error, e:
print e.out

View File

@ -17,8 +17,6 @@ class TestLinker(object):
linker.get_target, 'py.path.local')
assert relpath == 'path/local.html'
testspec = [
'a a/b a/b',
'/a /a/b a/b',
@ -28,17 +26,17 @@ testspec = [
'/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)
print "linking", frompath, "to", topath
assert result == expected
def test_gen_check():
for line in testspec:
frompath, topath, expected = line.split()
yield gen_check, frompath, topath, expected
yield gen_check, frompath, topath, expected,
def test_check_incompatible():
py.test.raises(ValueError, "relpath('/a', 'b')")