Skip to content

Commit

Permalink
fixup! intersphinx: Create an _InventoryItem type
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jan 16, 2025
1 parent fdeaf6a commit ee45e21
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 74 deletions.
39 changes: 22 additions & 17 deletions tests/test_builders/test_build_dirhtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from sphinx.util.inventory import InventoryFile
from sphinx.util.inventory import InventoryFile, _InventoryItem


@pytest.mark.sphinx('dirhtml', testroot='builder-dirhtml')
Expand All @@ -30,28 +30,33 @@ def test_dirhtml(app):
invdata = InventoryFile.load(f, 'path/to', posixpath.join)

assert 'index' in invdata.get('std:doc', {})
assert invdata['std:doc']['index'] == ('Project name not set', '', 'path/to/', '-')
assert invdata['std:doc']['index'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='path/to/',
display_name='-',
)

assert 'foo/index' in invdata.get('std:doc', {})
assert invdata['std:doc']['foo/index'] == (
'Project name not set',
'',
'path/to/foo/',
'-',
assert invdata['std:doc']['foo/index'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='path/to/foo/',
display_name='-',
)

assert 'index' in invdata.get('std:label', {})
assert invdata['std:label']['index'] == (
'Project name not set',
'',
'path/to/#index',
'-',
assert invdata['std:label']['index'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='path/to/#index',
display_name='-',
)

assert 'foo' in invdata.get('std:label', {})
assert invdata['std:label']['foo'] == (
'Project name not set',
'',
'path/to/foo/#foo',
'foo/index',
assert invdata['std:label']['foo'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='path/to/foo/#foo',
display_name='foo/index',
)
52 changes: 26 additions & 26 deletions tests/test_builders/test_build_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from sphinx._cli.util.errors import strip_escape_sequences
from sphinx.builders.html import validate_html_extra_path, validate_html_static_path
from sphinx.errors import ConfigError
from sphinx.util.inventory import InventoryFile
from sphinx.util.inventory import InventoryFile, _InventoryItem

from tests.test_builders.xpath_data import FIGURE_CAPTION
from tests.test_builders.xpath_util import check_xpath
Expand Down Expand Up @@ -233,36 +233,36 @@ def test_html_inventory(app):
'genindex',
'search',
}
assert invdata['std:label']['modindex'] == (
'Project name not set',
'',
'https://www.google.com/py-modindex.html',
'Module Index',
assert invdata['std:label']['modindex'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='https://www.google.com/py-modindex.html',
display_name='Module Index',
)
assert invdata['std:label']['py-modindex'] == (
'Project name not set',
'',
'https://www.google.com/py-modindex.html',
'Python Module Index',
assert invdata['std:label']['py-modindex'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='https://www.google.com/py-modindex.html',
display_name='Python Module Index',
)
assert invdata['std:label']['genindex'] == (
'Project name not set',
'',
'https://www.google.com/genindex.html',
'Index',
assert invdata['std:label']['genindex'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='https://www.google.com/genindex.html',
display_name='Index',
)
assert invdata['std:label']['search'] == (
'Project name not set',
'',
'https://www.google.com/search.html',
'Search Page',
assert invdata['std:label']['search'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='https://www.google.com/search.html',
display_name='Search Page',
)
assert set(invdata['std:doc'].keys()) == {'index'}
assert invdata['std:doc']['index'] == (
'Project name not set',
'',
'https://www.google.com/index.html',
'The basic Sphinx documentation for testing',
assert invdata['std:doc']['index'] == _InventoryItem(
project_name='Project name not set',
project_version='',
uri='https://www.google.com/index.html',
display_name='The basic Sphinx documentation for testing',
)


Expand Down
11 changes: 6 additions & 5 deletions tests/test_extensions/test_ext_intersphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
from sphinx.ext.intersphinx._resolve import missing_reference
from sphinx.ext.intersphinx._shared import _IntersphinxProject
from sphinx.util.inventory import _InventoryItem

from tests.test_util.intersphinx_data import (
INVENTORY_V2,
Expand Down Expand Up @@ -155,11 +156,11 @@ def test_missing_reference(tmp_path, app):
load_mappings(app)
inv = app.env.intersphinx_inventory

assert inv['py:module']['module2'] == (
'foo',
'2.0',
'https://docs.python.org/foo.html#module-module2',
'-',
assert inv['py:module']['module2'] == _InventoryItem(
project_name='foo',
project_version='2.0',
uri='https://docs.python.org/foo.html#module-module2',
display_name='-',
)

# check resolution when a target is found
Expand Down
52 changes: 26 additions & 26 deletions tests/test_util/test_util_inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import sphinx.locale
from sphinx.testing.util import SphinxTestApp
from sphinx.util.inventory import InventoryFile
from sphinx.util.inventory import InventoryFile, _InventoryItem

from tests.test_util.intersphinx_data import (
INVENTORY_V1,
Expand All @@ -23,35 +23,35 @@

def test_read_inventory_v1():
invdata = InventoryFile.loads(INVENTORY_V1, uri='/util')
assert invdata['py:module']['module'] == (
'foo',
'1.0',
'/util/foo.html#module-module',
'-',
assert invdata['py:module']['module'] == _InventoryItem(
project_name='foo',
project_version='1.0',
uri='/util/foo.html#module-module',
display_name='-',
)
assert invdata['py:class']['module.cls'] == (
'foo',
'1.0',
'/util/foo.html#module.cls',
'-',
assert invdata['py:class']['module.cls'] == _InventoryItem(
project_name='foo',
project_version='1.0',
uri='/util/foo.html#module.cls',
display_name='-',
)


def test_read_inventory_v2():
invdata = InventoryFile.loads(INVENTORY_V2, uri='/util')

assert len(invdata['py:module']) == 2
assert invdata['py:module']['module1'] == (
'foo',
'2.0',
'/util/foo.html#module-module1',
'Long Module desc',
assert invdata['py:module']['module1'] == _InventoryItem(
project_name='foo',
project_version='2.0',
uri='/util/foo.html#module-module1',
display_name='Long Module desc',
)
assert invdata['py:module']['module2'] == (
'foo',
'2.0',
'/util/foo.html#module-module2',
'-',
assert invdata['py:module']['module2'] == _InventoryItem(
project_name='foo',
project_version='2.0',
uri='/util/foo.html#module-module2',
display_name='-',
)
assert invdata['py:function']['module1.func'][2] == (
'/util/sub/foo.html#module1.func'
Expand All @@ -65,11 +65,11 @@ def test_read_inventory_v2():

def test_read_inventory_v2_not_having_version():
invdata = InventoryFile.loads(INVENTORY_V2_NO_VERSION, uri='/util')
assert invdata['py:module']['module1'] == (
'foo',
'',
'/util/foo.html#module-module1',
'Long Module desc',
assert invdata['py:module']['module1'] == _InventoryItem(
project_name='foo',
project_version='',
uri='/util/foo.html#module-module1',
display_name='Long Module desc',
)


Expand Down

0 comments on commit ee45e21

Please sign in to comment.