| 1 |
"""Test autosummary for import cycles.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from typing import TYPE_CHECKING |
| 6 |
|
| 7 |
import pytest |
| 8 |
from docutils import nodes |
| 9 |
|
| 10 |
from sphinx import addnodes |
| 11 |
from sphinx.ext.autosummary import autosummary_table |
| 12 |
from sphinx.testing.util import assert_node |
| 13 |
|
| 14 |
from tests.utils import extract_node |
| 15 |
|
| 16 |
if TYPE_CHECKING: |
| 17 |
from sphinx.testing.util import SphinxTestApp |
| 18 |
|
| 19 |
|
| 20 |
@pytest.mark.sphinx('dummy', testroot='ext-autosummary-import_cycle') |
| 21 |
@pytest.mark.usefixtures('rollback_sysmodules') |
| 22 |
def test_autosummary_import_cycle(app: SphinxTestApp) -> None: |
| 23 |
app.build() |
| 24 |
|
| 25 |
doctree = app.env.get_doctree('index') |
| 26 |
app.env.apply_post_transforms(doctree, 'index') |
| 27 |
|
| 28 |
assert len(list(doctree.findall(nodes.reference))) == 1 |
| 29 |
|
| 30 |
assert_node( |
| 31 |
doctree, |
| 32 |
( |
| 33 |
addnodes.index, # [0] |
| 34 |
nodes.target, # [1] |
| 35 |
nodes.paragraph, # [2] |
| 36 |
addnodes.tabular_col_spec, # [3] |
| 37 |
[ |
| 38 |
autosummary_table, |
| 39 |
nodes.table, |
| 40 |
nodes.tgroup, |
| 41 |
( |
| 42 |
nodes.colspec, # [4][0][0][0] |
| 43 |
nodes.colspec, # [4][0][0][1] |
| 44 |
[nodes.tbody, nodes.row], # [4][0][0][2][1] |
| 45 |
), |
| 46 |
], |
| 47 |
addnodes.index, # [5] |
| 48 |
addnodes.desc, # [6] |
| 49 |
), |
| 50 |
) |
| 51 |
assert_node( |
| 52 |
extract_node(doctree, 4, 0, 0, 2, 0), |
| 53 |
([nodes.entry, nodes.paragraph, (nodes.reference, nodes.Text)], nodes.entry), |
| 54 |
) |
| 55 |
assert_node( |
| 56 |
extract_node(doctree, 4, 0, 0, 2, 0, 0, 0, 0), |
| 57 |
nodes.reference, |
| 58 |
refid='spam.eggs.Ham', |
| 59 |
reftitle='spam.eggs.Ham', |
| 60 |
) |
| 61 |
|
| 62 |
expected = ( |
| 63 |
'Summarised items should not include the current module. ' |
| 64 |
"Replace 'spam.eggs.Ham' with 'Ham'." |
| 65 |
) |
| 66 |
assert expected in app.warning.getvalue() |
| 67 |
|
| 68 |
|
| 69 |
@pytest.mark.sphinx( |
| 70 |
'dummy', |
| 71 |
testroot='ext-autosummary-module_prefix', |
| 72 |
copy_test_root=True, |
| 73 |
) |
| 74 |
@pytest.mark.usefixtures('rollback_sysmodules') |
| 75 |
def test_autosummary_generate_prefixes(app: SphinxTestApp) -> None: |
| 76 |
app.build() |
| 77 |
warnings = app.warning.getvalue() |
| 78 |
assert 'Summarised items should not include the current module.' not in warnings |
| 79 |
assert warnings == '' |