diff --git a/tests/roots/commands/conf.py b/tests/roots/commands/conf.py new file mode 100644 index 0000000..49d78f3 --- /dev/null +++ b/tests/roots/commands/conf.py @@ -0,0 +1,6 @@ +import os +import sys + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +extensions = ['sphinx_click'] diff --git a/tests/roots/commands/greet.py b/tests/roots/commands/greet.py new file mode 100644 index 0000000..8981828 --- /dev/null +++ b/tests/roots/commands/greet.py @@ -0,0 +1,22 @@ +"""The greet example taken from the README.""" + +import click + + +@click.group() +def greet(): + """A sample command group.""" + pass + + +@greet.command() +@click.argument('user', envvar='USER') +def hello(user): + """Greet a user.""" + click.echo('Hello %s' % user) + + +@greet.command() +def world(): + """Greet the world.""" + click.echo('Hello world!') diff --git a/tests/roots/commands/index.rst b/tests/roots/commands/index.rst new file mode 100644 index 0000000..0b21582 --- /dev/null +++ b/tests/roots/commands/index.rst @@ -0,0 +1,6 @@ +Commands +======== + +.. click:: greet:greet + :prog: greet + :commands: world diff --git a/tests/roots/nested-full/index.rst b/tests/roots/nested-full/index.rst index 820eb23..ca32dd3 100644 --- a/tests/roots/nested-full/index.rst +++ b/tests/roots/nested-full/index.rst @@ -1,5 +1,5 @@ -Basics -====== +Nested (full) +============= .. click:: greet:greet :prog: greet diff --git a/tests/test_extension.py b/tests/test_extension.py index 91984d3..4dfd12d 100644 --- a/tests/test_extension.py +++ b/tests/test_extension.py @@ -44,8 +44,50 @@ def test_basics(make_app, rootdir): assert section[3].astext() == 'Commands' assert isinstance(section[4], sphinx_nodes.index) assert isinstance(section[5], sphinx_nodes.desc) + assert section[5].astext() == 'hello\n\nGreet a user.' assert isinstance(section[6], sphinx_nodes.index) assert isinstance(section[7], sphinx_nodes.desc) + assert section[7].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: + # literal_block: + # rubric: + # 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.literal_block) + + # we should only show a single command, 'world' + assert isinstance(section[3], nodes.rubric) + assert section[3].astext() == 'Commands' + assert isinstance(section[4], sphinx_nodes.index) + assert isinstance(section[5], sphinx_nodes.desc) + assert section[5].astext() == 'world\n\nGreet the world.' def test_nested_full(make_app, rootdir):