[svn r37774] Adding support for checking generated API links (for link roles).
--HG-- branch : trunk
This commit is contained in:
parent
df0736db08
commit
80a0045805
|
@ -15,7 +15,7 @@ option = py.test.config.addoptions("documentation check options",
|
||||||
)
|
)
|
||||||
|
|
||||||
_initialized = False
|
_initialized = False
|
||||||
def checkdocutils():
|
def checkdocutils(path):
|
||||||
global _initialized
|
global _initialized
|
||||||
try:
|
try:
|
||||||
import docutils
|
import docutils
|
||||||
|
@ -23,8 +23,8 @@ def checkdocutils():
|
||||||
py.test.skip("docutils not importable")
|
py.test.skip("docutils not importable")
|
||||||
if not _initialized:
|
if not _initialized:
|
||||||
from py.__.rest import directive
|
from py.__.rest import directive
|
||||||
directive.register_linkrole('api', resolve_linkrole)
|
directive.register_linkrole('api', get_resolve_linkrole(path))
|
||||||
directive.register_linkrole('source', resolve_linkrole)
|
directive.register_linkrole('source', get_resolve_linkrole(path))
|
||||||
_initialized = True
|
_initialized = True
|
||||||
|
|
||||||
def restcheck(path):
|
def restcheck(path):
|
||||||
|
@ -32,7 +32,7 @@ def restcheck(path):
|
||||||
if hasattr(path, 'localpath'):
|
if hasattr(path, 'localpath'):
|
||||||
localpath = path.localpath
|
localpath = path.localpath
|
||||||
_checkskip(localpath)
|
_checkskip(localpath)
|
||||||
checkdocutils()
|
checkdocutils(localpath)
|
||||||
import docutils.utils
|
import docutils.utils
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -234,17 +234,21 @@ 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):
|
||||||
|
# XXX yuck...
|
||||||
def resolve_linkrole(name, text):
|
def resolve_linkrole(name, text):
|
||||||
if name == 'api':
|
if name == 'api':
|
||||||
if text == 'py':
|
if text == 'py':
|
||||||
return 'py', '../../apigen/api/index.html'
|
ret = ('py', '../../apigen/api/index.html')
|
||||||
|
else:
|
||||||
assert text.startswith('py.'), (
|
assert text.startswith('py.'), (
|
||||||
'api link "%s" does not point to the py package') % (text,)
|
'api link "%s" does not point to the py package') % (text,)
|
||||||
dotted_name = text
|
dotted_name = text
|
||||||
if dotted_name.find('(') > -1:
|
if dotted_name.find('(') > -1:
|
||||||
dotted_name = dotted_name[:text.find('(')]
|
dotted_name = dotted_name[:text.find('(')]
|
||||||
dotted_name = '.'.join(dotted_name.split('.')[1:]) # remove pkg root
|
# remove pkg root
|
||||||
return text, '../../apigen/api/%s.html' % (dotted_name,)
|
dotted_name = '.'.join(dotted_name.split('.')[1:])
|
||||||
|
ret = (text, '../../apigen/api/%s.html' % (dotted_name,))
|
||||||
elif name == 'source':
|
elif name == 'source':
|
||||||
assert text.startswith('py/'), ('source link "%s" does not point '
|
assert text.startswith('py/'), ('source link "%s" does not point '
|
||||||
'to the py package') % (text,)
|
'to the py package') % (text,)
|
||||||
|
@ -253,5 +257,11 @@ def resolve_linkrole(name, text):
|
||||||
relpath += 'index.html'
|
relpath += 'index.html'
|
||||||
else:
|
else:
|
||||||
relpath += '.html'
|
relpath += '.html'
|
||||||
return text, '../../apigen/source/%s' % (relpath,)
|
ret = (text, '../../apigen/source/%s' % (relpath,))
|
||||||
|
if checkpath:
|
||||||
|
if not py.path.local(checkpath).join(ret[1]).check():
|
||||||
|
raise AssertionError(
|
||||||
|
'%s linkrole: %s points to non-existant path %s' % (
|
||||||
|
name, ret[0], ret[1]))
|
||||||
|
return ret
|
||||||
|
return resolve_linkrole
|
||||||
|
|
|
@ -70,7 +70,8 @@ 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 resolve_linkrole
|
from py.__.doc.conftest import get_resolve_linkrole
|
||||||
|
resolve_linkrole = get_resolve_linkrole(None)
|
||||||
assert resolve_linkrole('api', 'py.foo.bar') == (
|
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()') == (
|
||||||
|
@ -86,3 +87,14 @@ def test_resolve_linkrole():
|
||||||
'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():
|
||||||
|
from py.__.doc.conftest import get_resolve_linkrole
|
||||||
|
pypath = tmpdir.join('py')
|
||||||
|
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')")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue