2024-07-13 00:37:50 -05:00
|
|
|
"""Test autosummary for import cycles."""
|
|
|
|
|
2024-11-22 15:54:26 -06:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-07-13 00:37:50 -05:00
|
|
|
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')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_autosummary_import_cycle(app):
|
2024-07-13 00:37:50 -05:00
|
|
|
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',
|
|
|
|
)
|
2024-07-13 00:37:50 -05:00
|
|
|
|
|
|
|
expected = (
|
2024-08-11 08:58:56 -05:00
|
|
|
'Summarised items should not include the current module. '
|
2024-07-13 00:37:50 -05:00
|
|
|
"Replace 'spam.eggs.Ham' with 'Ham'."
|
|
|
|
)
|
|
|
|
assert expected in app.warning.getvalue()
|
2024-07-17 15:42:21 -05:00
|
|
|
|
|
|
|
|
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')
|
2024-07-23 09:35:55 -05:00
|
|
|
def test_autosummary_generate_prefixes(app):
|
2024-07-17 15:42:21 -05:00
|
|
|
app.build()
|
|
|
|
warnings = app.warning.getvalue()
|
|
|
|
assert 'Summarised items should not include the current module.' not in warnings
|
|
|
|
assert warnings == ''
|