summaryrefslogtreecommitdiff
path: root/tests/test_ext_intersphinx.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_ext_intersphinx.py')
-rw-r--r--tests/test_ext_intersphinx.py88
1 files changed, 17 insertions, 71 deletions
diff --git a/tests/test_ext_intersphinx.py b/tests/test_ext_intersphinx.py
index 869da42e1..86e56fd47 100644
--- a/tests/test_ext_intersphinx.py
+++ b/tests/test_ext_intersphinx.py
@@ -9,11 +9,8 @@
:license: BSD, see LICENSE for details.
"""
-import posixpath
import unittest
-import zlib
-from six import BytesIO
from docutils import nodes
import mock
import pytest
@@ -22,71 +19,16 @@ from io import BytesIO
from sphinx import addnodes
from sphinx.ext.intersphinx import setup as intersphinx_setup
-from sphinx.ext.intersphinx import read_inventory, \
- load_mappings, missing_reference, _strip_basic_auth, \
- _get_safe_url, fetch_inventory, INVENTORY_FILENAME, \
- debug
-
-
-inventory_v1 = '''\
-# Sphinx inventory version 1
-# Project: foo
-# Version: 1.0
-module mod foo.html
-module.cls class foo.html
-'''.encode('utf-8')
-
-inventory_v2 = '''\
-# Sphinx inventory version 2
-# Project: foo
-# Version: 2.0
-# The remainder of this file is compressed with zlib.
-'''.encode('utf-8') + zlib.compress('''\
-module1 py:module 0 foo.html#module-module1 Long Module desc
-module2 py:module 0 foo.html#module-$ -
-module1.func py:function 1 sub/foo.html#$ -
-CFunc c:function 2 cfunc.html#CFunc -
-a term std:term -1 glossary.html#term-a-term -
-a term including:colon std:term -1 glossary.html#term-a-term-including-colon -
-'''.encode('utf-8'))
-
-
-def test_read_inventory_v1():
- f = BytesIO(inventory_v1)
- invdata = read_inventory(f, '/util', posixpath.join)
- assert invdata['py:module']['module'] == \
- ('foo', '1.0', '/util/foo.html#module-module', '-')
- assert invdata['py:class']['module.cls'] == \
- ('foo', '1.0', '/util/foo.html#module.cls', '-')
-
-
-def test_read_inventory_v2():
- f = BytesIO(inventory_v2)
- invdata1 = read_inventory(f, '/util', posixpath.join)
-
- # try again with a small buffer size to test the chunking algorithm
- f = BytesIO(inventory_v2)
- invdata2 = read_inventory(f, '/util', posixpath.join, bufsize=5)
-
- assert invdata1 == invdata2
-
- assert len(invdata1['py:module']) == 2
- assert invdata1['py:module']['module1'] == \
- ('foo', '2.0', '/util/foo.html#module-module1', 'Long Module desc')
- assert invdata1['py:module']['module2'] == \
- ('foo', '2.0', '/util/foo.html#module-module2', '-')
- assert invdata1['py:function']['module1.func'][2] == \
- '/util/sub/foo.html#module1.func'
- assert invdata1['c:function']['CFunc'][2] == '/util/cfunc.html#CFunc'
- assert invdata1['std:term']['a term'][2] == \
- '/util/glossary.html#term-a-term'
- assert invdata1['std:term']['a term including:colon'][2] == \
- '/util/glossary.html#term-a-term-including-colon'
-
-
-@mock.patch('sphinx.ext.intersphinx.read_inventory')
+from sphinx.ext.intersphinx import (
+ load_mappings, missing_reference, _strip_basic_auth,
+ _get_safe_url, fetch_inventory, INVENTORY_FILENAME, debug
+)
+from test_util_inventory import inventory_v2
+
+
+@mock.patch('sphinx.ext.intersphinx.InventoryFile')
@mock.patch('sphinx.ext.intersphinx._read_from_url')
-def test_fetch_inventory_redirection(_read_from_url, read_inventory, app, status, warning):
+def test_fetch_inventory_redirection(_read_from_url, InventoryFile, app, status, warning):
intersphinx_setup(app)
_read_from_url().readline.return_value = '# Sphinx inventory version 2'.encode('utf-8')
@@ -94,7 +36,7 @@ def test_fetch_inventory_redirection(_read_from_url, read_inventory, app, status
_read_from_url().url = 'http://hostname/' + INVENTORY_FILENAME
fetch_inventory(app, 'http://hostname/', 'http://hostname/' + INVENTORY_FILENAME)
assert 'intersphinx inventory has moved' not in status.getvalue()
- assert read_inventory.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
# same uri and inv, redirected
status.seek(0)
@@ -105,7 +47,7 @@ def test_fetch_inventory_redirection(_read_from_url, read_inventory, app, status
assert status.getvalue() == ('intersphinx inventory has moved: '
'http://hostname/%s -> http://hostname/new/%s\n' %
(INVENTORY_FILENAME, INVENTORY_FILENAME))
- assert read_inventory.call_args[0][1] == 'http://hostname/new'
+ assert InventoryFile.load.call_args[0][1] == 'http://hostname/new'
# different uri and inv, not redirected
status.seek(0)
@@ -114,7 +56,7 @@ def test_fetch_inventory_redirection(_read_from_url, read_inventory, app, status
fetch_inventory(app, 'http://hostname/', 'http://hostname/new/' + INVENTORY_FILENAME)
assert 'intersphinx inventory has moved' not in status.getvalue()
- assert read_inventory.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
# different uri and inv, redirected
status.seek(0)
@@ -125,7 +67,7 @@ def test_fetch_inventory_redirection(_read_from_url, read_inventory, app, status
assert status.getvalue() == ('intersphinx inventory has moved: '
'http://hostname/new/%s -> http://hostname/other/%s\n' %
(INVENTORY_FILENAME, INVENTORY_FILENAME))
- assert read_inventory.call_args[0][1] == 'http://hostname/'
+ assert InventoryFile.load.call_args[0][1] == 'http://hostname/'
def test_missing_reference(tempdir, app, status, warning):
@@ -216,6 +158,10 @@ def test_missing_reference(tempdir, app, status, warning):
rn = reference_check('py', 'mod', 'py3krelparent:module1', 'foo', refdoc='sub/dir/test')
assert rn['refuri'] == '../../../../py3k/foo.html#module-module1'
+ # check refs of standard domain
+ rn = reference_check('std', 'doc', 'docname', 'docname')
+ assert rn['refuri'] == 'https://docs.python.org/docname.html'
+
def test_load_mappings_warnings(tempdir, app, status, warning):
"""