[svn r37782] Changed the checking in resolve_linkrole() so that instead of the apigen
results (the directory with HTML files) it uses the py lib object tree and source tree to find out whether links are valid. --HG-- branch : trunk
This commit is contained in:
parent
5bf17c3b62
commit
b8bb733778
|
@ -14,19 +14,18 @@ option = py.test.config.addoptions("documentation check options",
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
_initialized = False
|
||||||
def checkdocutils():
|
def checkdocutils():
|
||||||
|
global _initialized
|
||||||
try:
|
try:
|
||||||
import docutils
|
import docutils
|
||||||
except ImportError:
|
except ImportError:
|
||||||
py.test.skip("docutils not importable")
|
py.test.skip("docutils not importable")
|
||||||
|
if not _initialized:
|
||||||
def initrestdirectives(path):
|
from py.__.rest import directive
|
||||||
from py.__.rest import directive
|
directive.register_linkrole('api', resolve_linkrole)
|
||||||
dirpath = path.dirpath()
|
directive.register_linkrole('source', resolve_linkrole)
|
||||||
# XXX note that this gets called for every test, because the path is
|
_initialized = True
|
||||||
# different every test...
|
|
||||||
directive.register_linkrole('api', get_resolve_linkrole(dirpath))
|
|
||||||
directive.register_linkrole('source', get_resolve_linkrole(dirpath))
|
|
||||||
|
|
||||||
def restcheck(path):
|
def restcheck(path):
|
||||||
localpath = path
|
localpath = path
|
||||||
|
@ -34,7 +33,6 @@ def restcheck(path):
|
||||||
localpath = path.localpath
|
localpath = path.localpath
|
||||||
_checkskip(localpath)
|
_checkskip(localpath)
|
||||||
checkdocutils()
|
checkdocutils()
|
||||||
initrestdirectives(localpath)
|
|
||||||
import docutils.utils
|
import docutils.utils
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -236,35 +234,42 @@ class DocDirectory(py.test.collect.Directory):
|
||||||
return self.ReSTChecker(p, parent=self)
|
return self.ReSTChecker(p, parent=self)
|
||||||
Directory = DocDirectory
|
Directory = DocDirectory
|
||||||
|
|
||||||
def get_resolve_linkrole(checkpath=None):
|
def resolve_linkrole(name, text, check=True):
|
||||||
# XXX yuck...
|
if name == 'api':
|
||||||
def resolve_linkrole(name, text):
|
if text == 'py':
|
||||||
if name == 'api':
|
return ('py', '../../apigen/api/index.html')
|
||||||
if text == 'py':
|
else:
|
||||||
ret = ('py', '../../apigen/api/index.html')
|
assert text.startswith('py.'), (
|
||||||
else:
|
'api link "%s" does not point to the py package') % (text,)
|
||||||
assert text.startswith('py.'), (
|
dotted_name = text
|
||||||
'api link "%s" does not point to the py package') % (text,)
|
if dotted_name.find('(') > -1:
|
||||||
dotted_name = text
|
dotted_name = dotted_name[:text.find('(')]
|
||||||
if dotted_name.find('(') > -1:
|
# remove pkg root
|
||||||
dotted_name = dotted_name[:text.find('(')]
|
path = dotted_name.split('.')[1:]
|
||||||
# remove pkg root
|
dotted_name = '.'.join(path)
|
||||||
dotted_name = '.'.join(dotted_name.split('.')[1:])
|
obj = py
|
||||||
ret = (text, '../../apigen/api/%s.html' % (dotted_name,))
|
if check:
|
||||||
elif name == 'source':
|
for chunk in path:
|
||||||
assert text.startswith('py/'), ('source link "%s" does not point '
|
try:
|
||||||
'to the py package') % (text,)
|
obj = getattr(obj, chunk)
|
||||||
relpath = '/'.join(text.split('/')[1:])
|
except AttributeError:
|
||||||
if relpath.endswith('/') or not relpath:
|
raise AssertionError(
|
||||||
relpath += 'index.html'
|
'problem with linkrole :api:`%s`: can not resolve '
|
||||||
else:
|
'dotted name %s' % (text, dotted_name,))
|
||||||
relpath += '.html'
|
return (text, '../../apigen/api/%s.html' % (dotted_name,))
|
||||||
ret = (text, '../../apigen/source/%s' % (relpath,))
|
elif name == 'source':
|
||||||
if checkpath:
|
assert text.startswith('py/'), ('source link "%s" does not point '
|
||||||
if not py.path.local(checkpath).join(ret[1]).check():
|
'to the py package') % (text,)
|
||||||
raise AssertionError(
|
relpath = '/'.join(text.split('/')[1:])
|
||||||
'%s linkrole: %s points to non-existant path %s' % (
|
if check:
|
||||||
name, ret[0], py.path.local(checkpath).join(ret[1])))
|
pkgroot = py.__package__.getpath()
|
||||||
return ret
|
abspath = pkgroot.join(relpath)
|
||||||
return resolve_linkrole
|
assert pkgroot.join(relpath).check(), (
|
||||||
|
'problem with linkrole :source:`%s`: '
|
||||||
|
'path %s does not exist' % (text, relpath))
|
||||||
|
if relpath.endswith('/') or not relpath:
|
||||||
|
relpath += 'index.html'
|
||||||
|
else:
|
||||||
|
relpath += '.html'
|
||||||
|
return (text, '../../apigen/source/%s' % (relpath,))
|
||||||
|
|
||||||
|
|
|
@ -70,31 +70,30 @@ def test_js_ignore():
|
||||||
assert len(l+l2) == 3
|
assert len(l+l2) == 3
|
||||||
|
|
||||||
def test_resolve_linkrole():
|
def test_resolve_linkrole():
|
||||||
from py.__.doc.conftest import get_resolve_linkrole
|
from py.__.doc.conftest import resolve_linkrole
|
||||||
resolve_linkrole = get_resolve_linkrole(None)
|
assert resolve_linkrole('api', 'py.foo.bar', False) == (
|
||||||
assert resolve_linkrole('api', 'py.foo.bar') == (
|
|
||||||
'py.foo.bar', '../../apigen/api/foo.bar.html')
|
'py.foo.bar', '../../apigen/api/foo.bar.html')
|
||||||
assert resolve_linkrole('api', 'py.foo.bar()') == (
|
assert resolve_linkrole('api', 'py.foo.bar()', False) == (
|
||||||
'py.foo.bar()', '../../apigen/api/foo.bar.html')
|
'py.foo.bar()', '../../apigen/api/foo.bar.html')
|
||||||
assert resolve_linkrole('api', 'py') == (
|
assert resolve_linkrole('api', 'py', False) == (
|
||||||
'py', '../../apigen/api/index.html')
|
'py', '../../apigen/api/index.html')
|
||||||
py.test.raises(AssertionError, 'resolve_linkrole("api", "foo.bar")')
|
py.test.raises(AssertionError, 'resolve_linkrole("api", "foo.bar")')
|
||||||
assert resolve_linkrole('source', 'py/foo/bar.py') == (
|
assert resolve_linkrole('source', 'py/foo/bar.py', False) == (
|
||||||
'py/foo/bar.py', '../../apigen/source/foo/bar.py.html')
|
'py/foo/bar.py', '../../apigen/source/foo/bar.py.html')
|
||||||
assert resolve_linkrole('source', 'py/foo/') == (
|
assert resolve_linkrole('source', 'py/foo/', False) == (
|
||||||
'py/foo/', '../../apigen/source/foo/index.html')
|
'py/foo/', '../../apigen/source/foo/index.html')
|
||||||
assert resolve_linkrole('source', 'py/') == (
|
assert resolve_linkrole('source', 'py/', False) == (
|
||||||
'py/', '../../apigen/source/index.html')
|
'py/', '../../apigen/source/index.html')
|
||||||
py.test.raises(AssertionError, 'resolve_linkrole("source", "/foo/bar/")')
|
py.test.raises(AssertionError, 'resolve_linkrole("source", "/foo/bar/")')
|
||||||
|
|
||||||
def test_resolve_linkrole_relpath():
|
def test_resolve_linkrole_check_api():
|
||||||
from py.__.doc.conftest import get_resolve_linkrole
|
from py.__.doc.conftest import resolve_linkrole
|
||||||
pypath = tmpdir.join('py')
|
assert resolve_linkrole('api', 'py.test.ensuretemp')
|
||||||
docpath = pypath.join('doc')
|
|
||||||
apipath = tmpdir.join('apigen/api')
|
|
||||||
apipath.ensure('foo.bar.html')
|
|
||||||
resolve_linkrole = get_resolve_linkrole(docpath)
|
|
||||||
|
|
||||||
assert resolve_linkrole('api', 'py.foo.bar')
|
|
||||||
py.test.raises(AssertionError, "resolve_linkrole('api', 'py.foo.baz')")
|
py.test.raises(AssertionError, "resolve_linkrole('api', 'py.foo.baz')")
|
||||||
|
|
||||||
|
def test_resolve_linkrole_check_source():
|
||||||
|
from py.__.doc.conftest import resolve_linkrole
|
||||||
|
assert resolve_linkrole('source', 'py/path/common.py')
|
||||||
|
py.test.raises(AssertionError,
|
||||||
|
"resolve_linkrole('source', 'py/foo/bar.py')")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue