-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathtest_extension.py
More file actions
182 lines (151 loc) · 5.87 KB
/
Copy pathtest_extension.py
File metadata and controls
182 lines (151 loc) · 5.87 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import pickle
from docutils import nodes
from sphinx import addnodes as sphinx_nodes
def test_mock_import_compatibility():
"""Test that sphinx_click.ext.mock is callable after sphinx.ext.autodoc.mock is imported.
Regression test for https://github.com/click-contrib/sphinx-click/issues/159
When sphinx_autodoc_typehints imports `from sphinx.ext.autodoc.mock import mock`,
it causes Python to bind the submodule as an attribute on sphinx.ext.autodoc,
which can shadow the re-exported mock function. sphinx_click must import mock
directly from the submodule to avoid this issue.
"""
# Simulate sphinx_autodoc_typehints being loaded first
from sphinx.ext.autodoc.mock import mock # noqa: F401
# Now import sphinx_click (as would happen during Sphinx extension loading)
import sphinx_click.ext
# Verify the mock function is callable
with sphinx_click.ext.mock([]):
pass
def test_basics(make_app, rootdir):
srcdir = rootdir / 'basics'
app = make_app('xml', srcdir=srcdir)
app.build()
# TODO: rather than using the pickled doctree, we should decode the XML
content = pickle.loads((app.doctreedir / 'index.doctree').read_bytes())
# doc has format like so:
#
# document:
# section:
# title:
# section:
# title:
# paragraph:
# rubric: (Usage)
# literal_block:
# rubric: (Commands)
# index:
# desc:
# desc_signature:
# desc_signature:
# index:
# desc:
# desc_signature:
# desc_signature:
section = content[0][1]
assert isinstance(section, nodes.section)
assert isinstance(section[0], nodes.title)
assert section[0].astext() == 'greet'
assert isinstance(section[1], nodes.paragraph)
assert section[1].astext() == 'A sample command group.'
assert isinstance(section[2], nodes.rubric)
assert section[2].astext() == 'Usage'
assert isinstance(section[3], nodes.literal_block)
assert isinstance(section[4], nodes.rubric)
assert section[4].astext() == 'Commands'
assert isinstance(section[5], sphinx_nodes.index)
assert isinstance(section[6], sphinx_nodes.desc)
assert section[6].astext() == 'hello\n\nGreet a user.'
assert isinstance(section[7], sphinx_nodes.index)
assert isinstance(section[8], sphinx_nodes.desc)
assert section[8].astext() == 'world\n\nGreet the world.'
def test_commands(make_app, rootdir):
srcdir = rootdir / 'commands'
app = make_app('xml', srcdir=srcdir)
app.build()
# TODO: rather than using the pickled doctree, we should decode the XML
content = pickle.loads((app.doctreedir / 'index.doctree').read_bytes())
# doc has format like so:
#
# document:
# section:
# title:
# section:
# title:
# paragraph:
# rubric: (Usage)
# literal_block:
# rubric: (Commands)
# index:
# desc:
# desc_signature:
# desc_signature:
section = content[0][1]
assert isinstance(section, nodes.section)
assert isinstance(section[0], nodes.title)
assert section[0].astext() == 'greet'
assert isinstance(section[1], nodes.paragraph)
assert section[1].astext() == 'A sample command group.'
assert isinstance(section[2], nodes.rubric)
assert section[2].astext() == 'Usage'
assert isinstance(section[3], nodes.literal_block)
# we should only show a single command, 'world'
assert isinstance(section[4], nodes.rubric)
assert section[4].astext() == 'Commands'
assert isinstance(section[5], sphinx_nodes.index)
assert isinstance(section[6], sphinx_nodes.desc)
assert section[6].astext() == 'world\n\nGreet the world.'
def test_nested_full(make_app, rootdir):
srcdir = rootdir / 'nested-full'
app = make_app('xml', srcdir=srcdir)
app.build()
# TODO: rather than using the pickled doctree, we should decode the XML
content = pickle.loads((app.doctreedir / 'index.doctree').read_bytes())
# doc has format like so:
#
# document:
# section:
# title:
# section:
# title:
# paragraph:
# rubric: (Usage)
# literal_block:
# section:
# title
# paragraph
# rubric: (Usage)
# literal_block
# ...
# section:
# title
# paragraph
# rubric: (Usage)
# literal_block
section = content[0][1]
assert isinstance(section, nodes.section)
assert isinstance(section[0], nodes.title)
assert section[0].astext() == 'greet'
assert isinstance(section[1], nodes.paragraph)
assert section[1].astext() == 'A sample command group.'
assert isinstance(section[2], nodes.rubric)
assert section[2].astext() == 'Usage'
assert isinstance(section[3], nodes.literal_block)
subsection_a = section[4]
assert isinstance(subsection_a, nodes.section)
assert isinstance(subsection_a[0], nodes.title)
assert subsection_a[0].astext() == 'hello'
assert isinstance(subsection_a[1], nodes.paragraph)
assert subsection_a[1].astext() == 'Greet a user.'
assert isinstance(subsection_a[2], nodes.rubric)
assert subsection_a[2].astext() == 'Usage'
assert isinstance(subsection_a[3], nodes.literal_block)
# we don't need to verify the rest of this: that's done elsewhere
subsection_b = section[5]
assert isinstance(subsection_b, nodes.section)
assert isinstance(subsection_b[0], nodes.title)
assert subsection_b[0].astext() == 'world'
assert isinstance(subsection_b[1], nodes.paragraph)
assert subsection_b[1].astext() == 'Greet the world.'
assert isinstance(subsection_b[2], nodes.rubric)
assert subsection_b[2].astext() == 'Usage'
assert isinstance(subsection_b[3], nodes.literal_block)