|
| 1 | +"""Test object description directives.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from docutils import nodes |
| 5 | + |
| 6 | +from sphinx import addnodes |
| 7 | +from sphinx.io import create_publisher |
| 8 | +from sphinx.util.docutils import sphinx_domains |
| 9 | + |
| 10 | + |
| 11 | +def _doctree_for_test(builder, docname: str) -> nodes.document: |
| 12 | + builder.env.prepare_settings(docname) |
| 13 | + publisher = create_publisher(builder.app, 'restructuredtext') |
| 14 | + with sphinx_domains(builder.env): |
| 15 | + publisher.set_source(source_path=builder.env.doc2path(docname)) |
| 16 | + publisher.publish() |
| 17 | + return publisher.document |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.sphinx('text', testroot='object-description-sections') |
| 21 | +def test_object_description_sections(app): |
| 22 | + doctree = _doctree_for_test(app.builder, 'index') |
| 23 | + # <document> |
| 24 | + # <index> |
| 25 | + # <desc> |
| 26 | + # <desc_signature> |
| 27 | + # <desc_name> |
| 28 | + # func |
| 29 | + # <desc_parameterlist> |
| 30 | + # <desc_content> |
| 31 | + # <section> |
| 32 | + # <title> |
| 33 | + # Overview |
| 34 | + # <paragraph> |
| 35 | + # Lorem ipsum dolar sit amet |
| 36 | + |
| 37 | + assert isinstance(doctree[0], addnodes.index) |
| 38 | + assert isinstance(doctree[1], addnodes.desc) |
| 39 | + assert isinstance(doctree[1][0], addnodes.desc_signature) |
| 40 | + assert isinstance(doctree[1][1], addnodes.desc_content) |
| 41 | + assert isinstance(doctree[1][1][0], nodes.section) |
| 42 | + assert isinstance(doctree[1][1][0][0], nodes.title) |
| 43 | + assert doctree[1][1][0][0][0] == 'Overview' |
| 44 | + assert isinstance(doctree[1][1][0][1], nodes.paragraph) |
| 45 | + assert doctree[1][1][0][1][0] == 'Lorem ipsum dolar sit amet' |
0 commit comments