Skip to content

Commit 37742be

Browse files
committed
tests: Add tests for 'commands' option
Signed-off-by: Stephen Finucane <stephen@that.guru>
1 parent 1bcd407 commit 37742be

File tree

5 files changed

+78
-2
lines changed

5 files changed

+78
-2
lines changed

tests/roots/commands/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/commands/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/commands/index.rst

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

tests/roots/nested-full/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
Basics
2-
======
1+
Nested (full)
2+
=============
33

44
.. click:: greet:greet
55
:prog: greet

tests/test_extension.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,50 @@ def test_basics(make_app, rootdir):
4444
assert section[3].astext() == 'Commands'
4545
assert isinstance(section[4], sphinx_nodes.index)
4646
assert isinstance(section[5], sphinx_nodes.desc)
47+
assert section[5].astext() == 'hello\n\nGreet a user.'
4748
assert isinstance(section[6], sphinx_nodes.index)
4849
assert isinstance(section[7], sphinx_nodes.desc)
50+
assert section[7].astext() == 'world\n\nGreet the world.'
51+
52+
53+
def test_commands(make_app, rootdir):
54+
srcdir = rootdir / 'commands'
55+
app = make_app('xml', srcdir=srcdir)
56+
app.build()
57+
58+
# TODO: rather than using the pickled doctree, we should decode the XML
59+
content = pickle.loads((app.doctreedir / 'index.doctree').read_bytes())
60+
61+
# doc has format like so:
62+
#
63+
# document:
64+
# section:
65+
# title:
66+
# section:
67+
# title:
68+
# paragraph:
69+
# literal_block:
70+
# rubric:
71+
# index:
72+
# desc:
73+
# desc_signature:
74+
# desc_signature:
75+
76+
section = content[0][1]
77+
assert isinstance(section, nodes.section)
78+
79+
assert isinstance(section[0], nodes.title)
80+
assert section[0].astext() == 'greet'
81+
assert isinstance(section[1], nodes.paragraph)
82+
assert section[1].astext() == 'A sample command group.'
83+
assert isinstance(section[2], nodes.literal_block)
84+
85+
# we should only show a single command, 'world'
86+
assert isinstance(section[3], nodes.rubric)
87+
assert section[3].astext() == 'Commands'
88+
assert isinstance(section[4], sphinx_nodes.index)
89+
assert isinstance(section[5], sphinx_nodes.desc)
90+
assert section[5].astext() == 'world\n\nGreet the world.'
4991

5092

5193
def test_nested_full(make_app, rootdir):

0 commit comments

Comments
 (0)