Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Sep 8, 2022
1 parent 64d5993 commit 241b556
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
Empty file.
39 changes: 39 additions & 0 deletions tests/roots/test-toctree-domain-objects/domains.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
test-domain-objects
===================

.. py:module:: hello
.. py:function:: world() -> str
Prints "Hello, World!" to stdout

.. py:class:: HelloWorldPrinter
Controls printing of hello world

.. py:method:: set_language()
Sets the language of the HelloWorldPrinter instance

.. py:attribute:: output_count
Count of outputs of "Hello, World!"

.. py:method:: print_normal()
:async:
:classmethod:

Prints the normal form of "Hello, World!"

.. py:method:: print()
Prints "Hello, World!", including in the chosen language

.. py:function:: exit()
:module: sys

Quits the interpreter

.. js:function:: fetch(resource)

Fetches the given resource, returns a Promise
6 changes: 6 additions & 0 deletions tests/roots/test-toctree-domain-objects/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.. toctree::
:numbered:
:caption: Table of Contents
:name: mastertoc

domains
42 changes: 41 additions & 1 deletion tests/test_environment_toctree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from docutils import nodes
from docutils.nodes import bullet_list, comment, list_item, reference, title
from docutils.nodes import bullet_list, comment, list_item, literal, reference, title

from sphinx import addnodes
from sphinx.addnodes import compact_paragraph, only
Expand Down Expand Up @@ -126,6 +126,46 @@ def test_glob(app):
assert app.env.numbered_toctrees == set()


@pytest.mark.sphinx('dummy', testroot='toctree-domain-objects')
def test_domain_objects(app):
includefiles = ['domains']

app.build()

assert app.env.toc_num_entries['index'] == 0
assert app.env.toc_num_entries['domains'] == 9
assert app.env.toctree_includes['index'] == includefiles
for file in includefiles:
assert 'index' in app.env.files_to_rebuild[file]
assert app.env.glob_toctrees == set()
assert app.env.numbered_toctrees == {'index'}

# tocs
toctree = app.env.tocs['domains']
print(toctree[0][1][1][1][0])
assert_node(toctree,
[bullet_list, list_item, (compact_paragraph, # [0][0]
[bullet_list, (list_item, # [0][1][0]
[list_item, # [0][1][1]
(compact_paragraph, # [0][1][1][0]
[bullet_list, (list_item, # [0][1][1][1][0]
list_item,
list_item,
list_item)])], # [0][1][1][1][3]
list_item,
list_item)])]) # [0][1][1]

assert_node(toctree[0][0],
[compact_paragraph, reference, "test-domain-objects"])

assert_node(toctree[0][1][0],
[list_item, ([compact_paragraph, reference, literal, "hello.world()"])])

print(toctree[0][1][1][1][3])
assert_node(toctree[0][1][1][1][3],
[list_item, ([compact_paragraph, reference, literal, "hello.HelloWorldPrinter.print()"])])


@pytest.mark.sphinx('xml', testroot='toctree')
@pytest.mark.test_params(shared_result='test_environment_toctree_basic')
def test_get_toc_for(app):
Expand Down

0 comments on commit 241b556

Please sign in to comment.