Skip to content

Commit

Permalink
tests: Add more application tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Finucane <stephen@that.guru>
  • Loading branch information
stephenfin committed Jul 13, 2022
1 parent 17e8a81 commit d8a73b7
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/roots/nested-full/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import os
import sys

sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

extensions = ['sphinx_click']
22 changes: 22 additions & 0 deletions tests/roots/nested-full/greet.py
Original file line number Diff line number Diff line change
@@ -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!')
6 changes: 6 additions & 0 deletions tests/roots/nested-full/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Basics
======

.. click:: greet:greet
:prog: greet
:nested: full
56 changes: 56 additions & 0 deletions tests/test_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,59 @@ def test_basics(make_app, rootdir):
assert isinstance(section[5], sphinx_nodes.desc)
assert isinstance(section[6], sphinx_nodes.index)
assert isinstance(section[7], sphinx_nodes.desc)


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:
# literal_block:
# section:
# title
# paragraph
# literal_block
# ...
# section:
# title
# paragraph
# 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.literal_block)

subsection_a = section[3]
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.literal_block)
# we don't need to verify the rest of this: that's done elsewhere

subsection_b = section[4]
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.literal_block)

0 comments on commit d8a73b7

Please sign in to comment.