Skip to content

Commit 241b556

Browse files
committed
Add tests
1 parent 64d5993 commit 241b556

File tree

4 files changed

+86
-1
lines changed

4 files changed

+86
-1
lines changed

tests/roots/test-toctree-domain-objects/conf.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
test-domain-objects
2+
===================
3+
4+
.. py:module:: hello
5+
6+
.. py:function:: world() -> str
7+
8+
Prints "Hello, World!" to stdout
9+
10+
.. py:class:: HelloWorldPrinter
11+
12+
Controls printing of hello world
13+
14+
.. py:method:: set_language()
15+
16+
Sets the language of the HelloWorldPrinter instance
17+
18+
.. py:attribute:: output_count
19+
20+
Count of outputs of "Hello, World!"
21+
22+
.. py:method:: print_normal()
23+
:async:
24+
:classmethod:
25+
26+
Prints the normal form of "Hello, World!"
27+
28+
.. py:method:: print()
29+
30+
Prints "Hello, World!", including in the chosen language
31+
32+
.. py:function:: exit()
33+
:module: sys
34+
35+
Quits the interpreter
36+
37+
.. js:function:: fetch(resource)
38+
39+
Fetches the given resource, returns a Promise
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.. toctree::
2+
:numbered:
3+
:caption: Table of Contents
4+
:name: mastertoc
5+
6+
domains

tests/test_environment_toctree.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from docutils import nodes
5-
from docutils.nodes import bullet_list, comment, list_item, reference, title
5+
from docutils.nodes import bullet_list, comment, list_item, literal, reference, title
66

77
from sphinx import addnodes
88
from sphinx.addnodes import compact_paragraph, only
@@ -126,6 +126,46 @@ def test_glob(app):
126126
assert app.env.numbered_toctrees == set()
127127

128128

129+
@pytest.mark.sphinx('dummy', testroot='toctree-domain-objects')
130+
def test_domain_objects(app):
131+
includefiles = ['domains']
132+
133+
app.build()
134+
135+
assert app.env.toc_num_entries['index'] == 0
136+
assert app.env.toc_num_entries['domains'] == 9
137+
assert app.env.toctree_includes['index'] == includefiles
138+
for file in includefiles:
139+
assert 'index' in app.env.files_to_rebuild[file]
140+
assert app.env.glob_toctrees == set()
141+
assert app.env.numbered_toctrees == {'index'}
142+
143+
# tocs
144+
toctree = app.env.tocs['domains']
145+
print(toctree[0][1][1][1][0])
146+
assert_node(toctree,
147+
[bullet_list, list_item, (compact_paragraph, # [0][0]
148+
[bullet_list, (list_item, # [0][1][0]
149+
[list_item, # [0][1][1]
150+
(compact_paragraph, # [0][1][1][0]
151+
[bullet_list, (list_item, # [0][1][1][1][0]
152+
list_item,
153+
list_item,
154+
list_item)])], # [0][1][1][1][3]
155+
list_item,
156+
list_item)])]) # [0][1][1]
157+
158+
assert_node(toctree[0][0],
159+
[compact_paragraph, reference, "test-domain-objects"])
160+
161+
assert_node(toctree[0][1][0],
162+
[list_item, ([compact_paragraph, reference, literal, "hello.world()"])])
163+
164+
print(toctree[0][1][1][1][3])
165+
assert_node(toctree[0][1][1][1][3],
166+
[list_item, ([compact_paragraph, reference, literal, "hello.HelloWorldPrinter.print()"])])
167+
168+
129169
@pytest.mark.sphinx('xml', testroot='toctree')
130170
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
131171
def test_get_toc_for(app):

0 commit comments

Comments
 (0)