diff options
Diffstat (limited to 'tests/test_extensions/test_ext_intersphinx.py')
-rw-r--r-- | tests/test_extensions/test_ext_intersphinx.py | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/tests/test_extensions/test_ext_intersphinx.py b/tests/test_extensions/test_ext_intersphinx.py index ef5a9b1..d475c60 100644 --- a/tests/test_extensions/test_ext_intersphinx.py +++ b/tests/test_extensions/test_ext_intersphinx.py @@ -7,10 +7,8 @@ import pytest from docutils import nodes from sphinx import addnodes +from sphinx.builders.html import INVENTORY_FILENAME from sphinx.ext.intersphinx import ( - INVENTORY_FILENAME, - _get_safe_url, - _strip_basic_auth, fetch_inventory, inspect_main, load_mappings, @@ -18,9 +16,14 @@ from sphinx.ext.intersphinx import ( normalize_intersphinx_mapping, ) from sphinx.ext.intersphinx import setup as intersphinx_setup +from sphinx.ext.intersphinx._load import _get_safe_url, _strip_basic_auth from sphinx.util.console import strip_colors -from tests.test_util.intersphinx_data import INVENTORY_V2, INVENTORY_V2_NO_VERSION +from tests.test_util.intersphinx_data import ( + INVENTORY_V2, + INVENTORY_V2_AMBIGUOUS_TERMS, + INVENTORY_V2_NO_VERSION, +) from tests.utils import http_server @@ -46,8 +49,8 @@ def set_config(app, mapping): app.config.intersphinx_disabled_reftypes = [] -@mock.patch('sphinx.ext.intersphinx.InventoryFile') -@mock.patch('sphinx.ext.intersphinx._read_from_url') +@mock.patch('sphinx.ext.intersphinx._load.InventoryFile') +@mock.patch('sphinx.ext.intersphinx._load._read_from_url') def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status, warning): # NoQA: PT019 intersphinx_setup(app) _read_from_url().readline.return_value = b'# Sphinx inventory version 2' @@ -248,6 +251,24 @@ def test_missing_reference_stddomain(tmp_path, app, status, warning): assert rn.astext() == 'The Julia Domain' +def test_ambiguous_reference_warning(tmp_path, app, warning): + inv_file = tmp_path / 'inventory' + inv_file.write_bytes(INVENTORY_V2_AMBIGUOUS_TERMS) + set_config(app, { + 'cmd': ('https://docs.python.org/', str(inv_file)), + }) + + # load the inventory + normalize_intersphinx_mapping(app, app.config) + load_mappings(app) + + # term reference (case insensitive) + node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM') + missing_reference(app, app.env, node, contnode) + + assert 'multiple matches found for std:term:A TERM' in warning.getvalue() + + @pytest.mark.sphinx('html', testroot='ext-intersphinx-cppdomain') def test_missing_reference_cppdomain(tmp_path, app, status, warning): inv_file = tmp_path / 'inventory' |