File: test_ext_autosummary_imports.py

package info (click to toggle)
sphinx 8.2.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,712 kB
  • sloc: python: 105,846; javascript: 6,474; perl: 451; makefile: 178; sh: 37; xml: 19; ansic: 2
file content (77 lines) | stat: -rw-r--r-- 2,158 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Test autosummary for import cycles."""

from __future__ import annotations

from typing import TYPE_CHECKING

import pytest
from docutils import nodes

from sphinx import addnodes
from sphinx.ext.autosummary import autosummary_table
from sphinx.testing.util import assert_node

if TYPE_CHECKING:
    from sphinx.testing.util import SphinxTestApp


@pytest.mark.sphinx('dummy', testroot='ext-autosummary-import_cycle')
@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

    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 = (
        'Summarised items should not include the current module. '
        "Replace 'spam.eggs.Ham' with 'Ham'."
    )
    assert expected in app.warning.getvalue()


@pytest.mark.sphinx(
    'dummy',
    testroot='ext-autosummary-module_prefix',
    copy_test_root=True,
)
@pytest.mark.usefixtures('rollback_sysmodules')
def test_autosummary_generate_prefixes(app: SphinxTestApp) -> None:
    app.build()
    warnings = app.warning.getvalue()
    assert 'Summarised items should not include the current module.' not in warnings
    assert warnings == ''