summaryrefslogtreecommitdiffstats
path: root/tests/test_extensions/test_ext_intersphinx.py
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/test_extensions/test_ext_intersphinx.py (renamed from tests/test_ext_intersphinx.py)134
1 files changed, 75 insertions, 59 deletions
diff --git a/tests/test_ext_intersphinx.py b/tests/test_extensions/test_ext_intersphinx.py
index 82bec9e..ef5a9b1 100644
--- a/tests/test_ext_intersphinx.py
+++ b/tests/test_extensions/test_ext_intersphinx.py
@@ -18,9 +18,10 @@ from sphinx.ext.intersphinx import (
normalize_intersphinx_mapping,
)
from sphinx.ext.intersphinx import setup as intersphinx_setup
+from sphinx.util.console import strip_colors
-from .test_util_inventory import inventory_v2, inventory_v2_not_having_version
-from .utils import http_server
+from tests.test_util.intersphinx_data import INVENTORY_V2, INVENTORY_V2_NO_VERSION
+from tests.utils import http_server
def fake_node(domain, type, target, content, **attrs):
@@ -52,46 +53,46 @@ def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status,
_read_from_url().readline.return_value = b'# Sphinx inventory version 2'
# same uri and inv, not redirected
- _read_from_url().url = 'http://hostname/' + INVENTORY_FILENAME
- fetch_inventory(app, 'http://hostname/', 'http://hostname/' + INVENTORY_FILENAME)
+ _read_from_url().url = 'https://hostname/' + INVENTORY_FILENAME
+ fetch_inventory(app, 'https://hostname/', 'https://hostname/' + INVENTORY_FILENAME)
assert 'intersphinx inventory has moved' not in status.getvalue()
- assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'https://hostname/'
# same uri and inv, redirected
status.seek(0)
status.truncate(0)
- _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME
+ _read_from_url().url = 'https://hostname/new/' + INVENTORY_FILENAME
- fetch_inventory(app, 'http://hostname/', 'http://hostname/' + INVENTORY_FILENAME)
+ fetch_inventory(app, 'https://hostname/', 'https://hostname/' + INVENTORY_FILENAME)
assert status.getvalue() == ('intersphinx inventory has moved: '
- 'http://hostname/%s -> http://hostname/new/%s\n' %
+ 'https://hostname/%s -> https://hostname/new/%s\n' %
(INVENTORY_FILENAME, INVENTORY_FILENAME))
- assert InventoryFile.load.call_args[0][1] == 'http://hostname/new'
+ assert InventoryFile.load.call_args[0][1] == 'https://hostname/new'
# different uri and inv, not redirected
status.seek(0)
status.truncate(0)
- _read_from_url().url = 'http://hostname/new/' + INVENTORY_FILENAME
+ _read_from_url().url = 'https://hostname/new/' + INVENTORY_FILENAME
- fetch_inventory(app, 'http://hostname/', 'http://hostname/new/' + INVENTORY_FILENAME)
+ fetch_inventory(app, 'https://hostname/', 'https://hostname/new/' + INVENTORY_FILENAME)
assert 'intersphinx inventory has moved' not in status.getvalue()
- assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'https://hostname/'
# different uri and inv, redirected
status.seek(0)
status.truncate(0)
- _read_from_url().url = 'http://hostname/other/' + INVENTORY_FILENAME
+ _read_from_url().url = 'https://hostname/other/' + INVENTORY_FILENAME
- fetch_inventory(app, 'http://hostname/', 'http://hostname/new/' + INVENTORY_FILENAME)
+ fetch_inventory(app, 'https://hostname/', 'https://hostname/new/' + INVENTORY_FILENAME)
assert status.getvalue() == ('intersphinx inventory has moved: '
- 'http://hostname/new/%s -> http://hostname/other/%s\n' %
+ 'https://hostname/new/%s -> https://hostname/other/%s\n' %
(INVENTORY_FILENAME, INVENTORY_FILENAME))
- assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'https://hostname/'
def test_missing_reference(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'https://docs.python.org/': str(inv_file),
'py3k': ('https://docs.python.org/py3k/', str(inv_file)),
@@ -169,7 +170,7 @@ def test_missing_reference(tmp_path, app, status, warning):
def test_missing_reference_pydomain(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'https://docs.python.org/': str(inv_file),
})
@@ -196,20 +197,10 @@ def test_missing_reference_pydomain(tmp_path, app, status, warning):
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == 'Foo.bar'
- # term reference (normal)
- node, contnode = fake_node('std', 'term', 'a term', 'a term')
- rn = missing_reference(app, app.env, node, contnode)
- assert rn.astext() == 'a term'
-
- # term reference (case insensitive)
- node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
- rn = missing_reference(app, app.env, node, contnode)
- assert rn.astext() == 'A TERM'
-
def test_missing_reference_stddomain(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'cmd': ('https://docs.python.org/', str(inv_file)),
})
@@ -236,11 +227,31 @@ def test_missing_reference_stddomain(tmp_path, app, status, warning):
rn = missing_reference(app, app.env, node, contnode)
assert rn.astext() == '-l'
+ # term reference (normal)
+ node, contnode = fake_node('std', 'term', 'a term', 'a term')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'a term'
+
+ # term reference (case insensitive)
+ node, contnode = fake_node('std', 'term', 'A TERM', 'A TERM')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'A TERM'
+
+ # label reference (normal)
+ node, contnode = fake_node('std', 'ref', 'The-Julia-Domain', 'The-Julia-Domain')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'The Julia Domain'
+
+ # label reference (case insensitive)
+ node, contnode = fake_node('std', 'ref', 'the-julia-domain', 'the-julia-domain')
+ rn = missing_reference(app, app.env, node, contnode)
+ assert rn.astext() == 'The Julia Domain'
+
@pytest.mark.sphinx('html', testroot='ext-intersphinx-cppdomain')
def test_missing_reference_cppdomain(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'https://docs.python.org/': str(inv_file),
})
@@ -266,7 +277,7 @@ def test_missing_reference_cppdomain(tmp_path, app, status, warning):
def test_missing_reference_jsdomain(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'https://docs.python.org/': str(inv_file),
})
@@ -290,7 +301,7 @@ def test_missing_reference_jsdomain(tmp_path, app, status, warning):
def test_missing_reference_disabled_domain(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'inv': ('https://docs.python.org/', str(inv_file)),
})
@@ -352,7 +363,7 @@ def test_missing_reference_disabled_domain(tmp_path, app, status, warning):
def test_inventory_not_having_version(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2_not_having_version)
+ inv_file.write_bytes(INVENTORY_V2_NO_VERSION)
set_config(app, {
'https://docs.python.org/': str(inv_file),
})
@@ -374,14 +385,14 @@ def test_load_mappings_warnings(tmp_path, app, status, warning):
identifiers are not string
"""
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {
'https://docs.python.org/': str(inv_file),
'py3k': ('https://docs.python.org/py3k/', str(inv_file)),
- 'repoze.workflow': ('http://docs.repoze.org/workflow/', str(inv_file)),
- 'django-taggit': ('http://django-taggit.readthedocs.org/en/latest/',
+ 'repoze.workflow': ('https://docs.repoze.org/workflow/', str(inv_file)),
+ 'django-taggit': ('https://django-taggit.readthedocs.org/en/latest/',
str(inv_file)),
- 12345: ('http://www.sphinx-doc.org/en/stable/', str(inv_file)),
+ 12345: ('https://www.sphinx-doc.org/en/stable/', str(inv_file)),
})
# load the inventory and check if it's done correctly
@@ -395,7 +406,7 @@ def test_load_mappings_warnings(tmp_path, app, status, warning):
def test_load_mappings_fallback(tmp_path, app, status, warning):
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
set_config(app, {})
# connect to invalid path
@@ -429,23 +440,25 @@ def test_load_mappings_fallback(tmp_path, app, status, warning):
class TestStripBasicAuth:
"""Tests for sphinx.ext.intersphinx._strip_basic_auth()"""
+
def test_auth_stripped(self):
- """basic auth creds stripped from URL containing creds"""
+ """Basic auth creds stripped from URL containing creds"""
url = 'https://user:12345@domain.com/project/objects.inv'
expected = 'https://domain.com/project/objects.inv'
actual = _strip_basic_auth(url)
assert expected == actual
def test_no_auth(self):
- """url unchanged if param doesn't contain basic auth creds"""
+ """Url unchanged if param doesn't contain basic auth creds"""
url = 'https://domain.com/project/objects.inv'
expected = 'https://domain.com/project/objects.inv'
actual = _strip_basic_auth(url)
assert expected == actual
def test_having_port(self):
- """basic auth creds correctly stripped from URL containing creds even if URL
- contains port"""
+ """Basic auth creds correctly stripped from URL containing creds even if URL
+ contains port
+ """
url = 'https://user:12345@domain.com:8080/project/objects.inv'
expected = 'https://domain.com:8080/project/objects.inv'
actual = _strip_basic_auth(url)
@@ -492,7 +505,7 @@ def test_inspect_main_noargs(capsys):
def test_inspect_main_file(capsys, tmp_path):
"""inspect_main interface, with file argument"""
inv_file = tmp_path / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
inspect_main([str(inv_file)])
@@ -507,15 +520,14 @@ def test_inspect_main_url(capsys):
def do_GET(self):
self.send_response(200, "OK")
self.end_headers()
- self.wfile.write(inventory_v2)
+ self.wfile.write(INVENTORY_V2)
def log_message(*args, **kwargs):
# Silenced.
pass
- url = 'http://localhost:7777/' + INVENTORY_FILENAME
-
- with http_server(InventoryHandler):
+ with http_server(InventoryHandler) as server:
+ url = f'http://localhost:{server.server_port}/{INVENTORY_FILENAME}'
inspect_main([url])
stdout, stderr = capsys.readouterr()
@@ -526,9 +538,9 @@ def test_inspect_main_url(capsys):
@pytest.mark.sphinx('html', testroot='ext-intersphinx-role')
def test_intersphinx_role(app, warning):
inv_file = app.srcdir / 'inventory'
- inv_file.write_bytes(inventory_v2)
+ inv_file.write_bytes(INVENTORY_V2)
app.config.intersphinx_mapping = {
- 'inv': ('http://example.org/', str(inv_file)),
+ 'inv': ('https://example.org/', str(inv_file)),
}
app.config.intersphinx_cache_limit = 0
app.config.nitpicky = True
@@ -539,22 +551,27 @@ def test_intersphinx_role(app, warning):
app.build()
content = (app.outdir / 'index.html').read_text(encoding='utf8')
- wStr = warning.getvalue()
-
- html = '<a class="reference external" href="http://example.org/{}" title="(in foo v2.0)">'
+ warnings = strip_colors(warning.getvalue()).splitlines()
+ index_path = app.srcdir / 'index.rst'
+ assert warnings == [
+ f"{index_path}:21: WARNING: role for external cross-reference not found in domain 'py': 'nope'",
+ f"{index_path}:28: WARNING: role for external cross-reference not found in domains 'cpp', 'std': 'nope'",
+ f"{index_path}:39: WARNING: inventory for external cross-reference not found: 'invNope'",
+ f"{index_path}:44: WARNING: role for external cross-reference not found in domain 'c': 'function' (perhaps you meant one of: 'func', 'identifier', 'type')",
+ f"{index_path}:45: WARNING: role for external cross-reference not found in domains 'cpp', 'std': 'function' (perhaps you meant one of: 'cpp:func', 'cpp:identifier', 'cpp:type')",
+ f'{index_path}:9: WARNING: external py:mod reference target not found: module3',
+ f'{index_path}:14: WARNING: external py:mod reference target not found: module10',
+ f'{index_path}:19: WARNING: external py:meth reference target not found: inv:Foo.bar',
+ ]
+
+ html = '<a class="reference external" href="https://example.org/{}" title="(in foo v2.0)">'
assert html.format('foo.html#module-module1') in content
assert html.format('foo.html#module-module2') in content
- assert "WARNING: external py:mod reference target not found: module3" in wStr
- assert "WARNING: external py:mod reference target not found: module10" in wStr
assert html.format('sub/foo.html#module1.func') in content
- assert "WARNING: external py:meth reference target not found: inv:Foo.bar" in wStr
-
- assert "WARNING: role for external cross-reference not found: py:nope" in wStr
# default domain
assert html.format('index.html#std_uint8_t') in content
- assert "WARNING: role for external cross-reference not found: nope" in wStr
# std roles without domain prefix
assert html.format('docname.html') in content
@@ -562,7 +579,6 @@ def test_intersphinx_role(app, warning):
# explicit inventory
assert html.format('cfunc.html#CFunc') in content
- assert "WARNING: inventory for external cross-reference not found: invNope" in wStr
# explicit title
assert html.format('index.html#foons') in content