sphinx/tests/test_extensions/test_ext_autosummary_imports.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

73 lines
2.0 KiB
Python
Raw Normal View History

"""Test autosummary for import cycles."""
from __future__ import annotations
import pytest
from docutils import nodes
from sphinx import addnodes
from sphinx.ext.autosummary import autosummary_table
from sphinx.testing.util import assert_node
@pytest.mark.sphinx('dummy', testroot='ext-autosummary-import_cycle')
2024-08-11 08:58:56 -05:00
@pytest.mark.usefixtures('rollback_sysmodules')
def test_autosummary_import_cycle(app):
app.build()
doctree = app.env.get_doctree('index')
app.env.apply_post_transforms(doctree, 'index')
assert len(list(doctree.findall(nodes.reference))) == 1
2024-08-11 08:58:56 -05:00
assert_node(
doctree,
(
addnodes.index, # [0]
nodes.target, # [1]
nodes.paragraph, # [2]
addnodes.tabular_col_spec, # [3]
[
autosummary_table,
nodes.table,
nodes.tgroup,
(
nodes.colspec, # [4][0][0][0]
nodes.colspec, # [4][0][0][1]
[nodes.tbody, nodes.row], # [4][0][0][2][1]
),
],
addnodes.index, # [5]
addnodes.desc, # [6]
),
)
assert_node(
doctree[4][0][0][2][0],
([nodes.entry, nodes.paragraph, (nodes.reference, nodes.Text)], nodes.entry),
)
assert_node(
doctree[4][0][0][2][0][0][0][0],
nodes.reference,
refid='spam.eggs.Ham',
reftitle='spam.eggs.Ham',
)
expected = (
2024-08-11 08:58:56 -05:00
'Summarised items should not include the current module. '
"Replace 'spam.eggs.Ham' with 'Ham'."
)
assert expected in app.warning.getvalue()
2025-01-31 12:04:36 -06:00
@pytest.mark.sphinx(
'dummy',
testroot='ext-autosummary-module_prefix',
copy_test_root=True,
)
2024-08-11 08:58:56 -05:00
@pytest.mark.usefixtures('rollback_sysmodules')
def test_autosummary_generate_prefixes(app):
app.build()
warnings = app.warning.getvalue()
assert 'Summarised items should not include the current module.' not in warnings
assert warnings == ''