Skip to content

Commit d8a73b7

Browse files
committed
tests: Add more application tests
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 17e8a81 commit d8a73b7

File tree

4 files changed

+90
-0
lines changed

4 files changed

+90
-0
lines changed

tests/roots/nested-full/conf.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
import sys
3+
4+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
5+
6+
extensions = ['sphinx_click']

tests/roots/nested-full/greet.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""The greet example taken from the README."""
2+
3+
import click
4+
5+
6+
@click.group()
7+
def greet():
8+
"""A sample command group."""
9+
pass
10+
11+
12+
@greet.command()
13+
@click.argument('user', envvar='USER')
14+
def hello(user):
15+
"""Greet a user."""
16+
click.echo('Hello %s' % user)
17+
18+
19+
@greet.command()
20+
def world():
21+
"""Greet the world."""
22+
click.echo('Hello world!')

tests/roots/nested-full/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Basics
2+
======
3+
4+
.. click:: greet:greet
5+
:prog: greet
6+
:nested: full

tests/test_extension.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,59 @@ def test_basics(make_app, rootdir):
4646
assert isinstance(section[5], sphinx_nodes.desc)
4747
assert isinstance(section[6], sphinx_nodes.index)
4848
assert isinstance(section[7], sphinx_nodes.desc)
49+
50+
51+
def test_nested_full(make_app, rootdir):
52+
srcdir = rootdir / 'nested-full'
53+
app = make_app('xml', srcdir=srcdir)
54+
app.build()
55+
56+
# TODO: rather than using the pickled doctree, we should decode the XML
57+
content = pickle.loads((app.doctreedir / 'index.doctree').read_bytes())
58+
59+
# doc has format like so:
60+
#
61+
# document:
62+
# section:
63+
# title:
64+
# section:
65+
# title:
66+
# paragraph:
67+
# literal_block:
68+
# section:
69+
# title
70+
# paragraph
71+
# literal_block
72+
# ...
73+
# section:
74+
# title
75+
# paragraph
76+
# literal_block
77+
78+
section = content[0][1]
79+
assert isinstance(section, nodes.section)
80+
81+
assert isinstance(section[0], nodes.title)
82+
assert section[0].astext() == 'greet'
83+
assert isinstance(section[1], nodes.paragraph)
84+
assert section[1].astext() == 'A sample command group.'
85+
assert isinstance(section[2], nodes.literal_block)
86+
87+
subsection_a = section[3]
88+
assert isinstance(subsection_a, nodes.section)
89+
90+
assert isinstance(subsection_a[0], nodes.title)
91+
assert subsection_a[0].astext() == 'hello'
92+
assert isinstance(subsection_a[1], nodes.paragraph)
93+
assert subsection_a[1].astext() == 'Greet a user.'
94+
assert isinstance(subsection_a[2], nodes.literal_block)
95+
# we don't need to verify the rest of this: that's done elsewhere
96+
97+
subsection_b = section[4]
98+
assert isinstance(subsection_b, nodes.section)
99+
100+
assert isinstance(subsection_b[0], nodes.title)
101+
assert subsection_b[0].astext() == 'world'
102+
assert isinstance(subsection_b[1], nodes.paragraph)
103+
assert subsection_b[1].astext() == 'Greet the world.'
104+
assert isinstance(subsection_b[2], nodes.literal_block)

0 commit comments

Comments
 (0)