Further fix for intersphinx labels, add test cases for that.

This commit is contained in:
Georg Brandl 2010-07-27 13:20:58 +02:00
parent bf71b0b2fa
commit 0aafe2ac1d
3 changed files with 35 additions and 5 deletions

View File

@ -1,6 +1,9 @@
Release 1.0.1 (in development)
==============================
* Fix display names for objects linked to by intersphinx with
explicit targets.
* Fix building with the JSON builder.
* Fix hyperrefs in object descriptions for LaTeX.

View File

@ -209,8 +209,8 @@ def missing_reference(app, env, node, contnode):
dispname = target
newnode.append(contnode.__class__(dispname, dispname))
return newnode
# at least get rid of the ':' in the target
if in_set is not None:
# at least get rid of the ':' in the target if no explicit title given
if in_set is not None and not node.get('refexplicit', True):
if len(contnode) and isinstance(contnode[0], nodes.Text):
contnode[0] = nodes.Text(newtarget, contnode[0].rawsource)

View File

@ -80,7 +80,10 @@ def test_read_inventory_v2():
def test_missing_reference(tempdir, app):
inv_file = tempdir / 'inventory'
write_file(inv_file, inventory_v2)
app.config.intersphinx_mapping = {'http://docs.python.org/': inv_file}
app.config.intersphinx_mapping = {
'http://docs.python.org/': inv_file,
'py3k': ('http://docs.python.org/py3k/', inv_file),
}
app.config.intersphinx_cache_limit = 0
# load the inventory and check if it's done correctly
@ -91,7 +94,7 @@ def test_missing_reference(tempdir, app):
('foo', '2.0', 'http://docs.python.org/foo.html#module-module2', '-')
# create fake nodes and check referencing
contnode = nodes.emphasis('foo')
contnode = nodes.emphasis('foo', 'foo')
refnode = addnodes.pending_xref('')
refnode['reftarget'] = 'module1.func'
refnode['reftype'] = 'func'
@ -101,7 +104,7 @@ def test_missing_reference(tempdir, app):
assert isinstance(rn, nodes.reference)
assert rn['refuri'] == 'http://docs.python.org/sub/foo.html#module1.func'
assert rn['reftitle'] == '(in foo v2.0)'
assert rn[0] is contnode
assert rn[0].astext() == 'module1.func'
# create unresolvable nodes and check None return value
refnode['reftype'] = 'foo'
@ -110,3 +113,27 @@ def test_missing_reference(tempdir, app):
refnode['reftype'] = 'function'
refnode['reftarget'] = 'foo.func'
assert missing_reference(app, app.env, refnode, contnode) is None
# check handling of prefixes
# prefix given, target found: prefix is stripped
refnode['reftype'] = 'mod'
refnode['reftarget'] = 'py3k:module2'
rn = missing_reference(app, app.env, refnode, contnode)
assert rn[0].astext() == 'module2'
# prefix given, target not found and nonexplicit title: prefix is stripped
refnode['reftarget'] = 'py3k:unknown'
refnode['refexplicit'] = False
contnode[0] = nodes.Text('py3k:unknown')
rn = missing_reference(app, app.env, refnode, contnode)
assert rn is None
assert contnode[0].astext() == 'unknown'
# prefix given, target not found and explicit title: nothing is changed
refnode['reftarget'] = 'py3k:unknown'
refnode['refexplicit'] = True
contnode[0] = nodes.Text('py3k:unknown')
rn = missing_reference(app, app.env, refnode, contnode)
assert rn is None
assert contnode[0].astext() == 'py3k:unknown'