Skip to content

Commit

Permalink
Add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Jul 13, 2024
1 parent 87ffd81 commit 24fc90a
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sphinx/environment/collectors/toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def build_toc(
entries.append(onlynode)
# check within the section for other node types
elif isinstance(sectionnode, nodes.Element):
# cache of parents -> list item
memo_parents: dict[nodes.Element, nodes.Element] = {}
# cache of parent node -> list item
memo_parents: dict[nodes.Element, nodes.list_item] = {}
toctreenode: nodes.Node
for toctreenode in sectionnode.findall():
if isinstance(toctreenode, nodes.section):
Expand Down
23 changes: 23 additions & 0 deletions tests/roots/test-toctree-domain-objects/document_scoping.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Level 1
=======

.. py:class:: ClassLevel1a
ClassLevel1b
.. py:method:: f()
.. py:method:: ClassLevel1a.g()
.. py:method:: ClassLevel1b.g()
Level 2
-------

.. py:class:: ClassLevel2a
ClassLevel2b
.. py:method:: f()
.. py:method:: ClassLevel2a.g()
.. py:method:: ClassLevel2b.g()
1 change: 1 addition & 0 deletions tests/roots/test-toctree-domain-objects/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
:name: mastertoc

domains
document_scoping
35 changes: 35 additions & 0 deletions tests/test_environment/test_environment_toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,41 @@ def test_domain_objects(app):
[list_item, ([compact_paragraph, reference, literal, "HelloWorldPrinter.print()"])])


@pytest.mark.sphinx('dummy', testroot='toctree-domain-objects')
def test_domain_objects_document_scoping(app):
app.build()

# tocs
toctree = app.env.tocs['document_scoping']
assert_node(
toctree,
[bullet_list, list_item, (
compact_paragraph, # [0][0]
[bullet_list, ( # [0][1]
[list_item, compact_paragraph, reference, literal, 'ClassLevel1a'], # [0][1][0]
[list_item, ( # [0][1][1]
[compact_paragraph, reference, literal, 'ClassLevel1b'], # [0][1][1][0]
[bullet_list, list_item, compact_paragraph, reference, literal, 'ClassLevel1b.f()'], # [0][1][1][1][0]
)],
[list_item, compact_paragraph, reference, literal, 'ClassLevel1a.g()'], # [0][1][2]
[list_item, compact_paragraph, reference, literal, 'ClassLevel1b.g()'], # [0][1][3]
[list_item, ( # [0][1][4]
[compact_paragraph, reference, 'Level 2'], # [0][1][4][0]
[bullet_list, ( # [0][1][4][1]
[list_item, compact_paragraph, reference, literal, 'ClassLevel2a'], # [0][1][4][1][0]
[list_item, ( # [0][1][4][1][1]
[compact_paragraph, reference, literal, 'ClassLevel2b'], # [0][1][4][1][1][0]
[bullet_list, list_item, compact_paragraph, reference, literal, 'ClassLevel2b.f()'], # [0][1][4][1][1][1][0]
)],
[list_item, compact_paragraph, reference, literal, 'ClassLevel2a.g()'], # [0][1][4][1][2]
[list_item, compact_paragraph, reference, literal, 'ClassLevel2b.g()'], # [0][1][4][1][3]
)],
)],
)],
)],
)


@pytest.mark.sphinx('xml', testroot='toctree')
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
def test_document_toc(app):
Expand Down

0 comments on commit 24fc90a

Please sign in to comment.