test: Add testcase for relative/short xref for py domain

This commit is contained in:
Takeshi KOMIYA 2021-01-11 03:12:39 +09:00
parent 7acafa991b
commit a3df1d00c7
2 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,10 @@
abbrev
======
.. currentmodule:: module_a.submodule
* normal: :py:meth:`module_a.submodule.ModTopLevel.mod_child_1`
* relative: :py:meth:`.ModTopLevel.mod_child_1`
* short name: :py:meth:`~module_a.submodule.ModTopLevel.mod_child_1`
* relative + short name: :py:meth:`~.ModTopLevel.mod_child_1`
* short name + relative: :py:meth:`~.ModTopLevel.mod_child_1`

View File

@ -8,6 +8,7 @@
:license: BSD, see LICENSE for details.
"""
import re
import sys
from unittest.mock import Mock
@ -132,6 +133,29 @@ def test_domain_py_xrefs(app, status, warning):
assert len(refnodes) == 2
@pytest.mark.sphinx('html', testroot='domain-py')
def test_domain_py_xrefs_abbreviations(app, status, warning):
app.builder.build_all()
content = (app.outdir / 'abbr.html').read_text()
assert re.search(r'normal: <a .* href="module.html#module_a.submodule.ModTopLevel.'
r'mod_child_1" .*><.*>module_a.submodule.ModTopLevel.mod_child_1\(\)'
r'<.*></a>',
content)
assert re.search(r'relative: <a .* href="module.html#module_a.submodule.ModTopLevel.'
r'mod_child_1" .*><.*>ModTopLevel.mod_child_1\(\)<.*></a>',
content)
assert re.search(r'short name: <a .* href="module.html#module_a.submodule.ModTopLevel.'
r'mod_child_1" .*><.*>mod_child_1\(\)<.*></a>',
content)
assert re.search(r'relative \+ short name: <a .* href="module.html#module_a.submodule.'
r'ModTopLevel.mod_child_1" .*><.*>mod_child_1\(\)<.*></a>',
content)
assert re.search(r'short name \+ relative: <a .* href="module.html#module_a.submodule.'
r'ModTopLevel.mod_child_1" .*><.*>mod_child_1\(\)<.*></a>',
content)
@pytest.mark.sphinx('dummy', testroot='domain-py')
def test_domain_py_objects(app, status, warning):
app.builder.build_all()