Commits

Georg Brandl  committed fb80220

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

  • Participants
  • Parent commits 148369c

Comments (0)

Files changed (3)

 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.

File sphinx/ext/intersphinx.py

                 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)
 

File tests/test_intersphinx.py

 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
            ('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'
     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'
     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'