Skip to content

Commit

Permalink
Rearrange tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AA-Turner committed Apr 27, 2024
1 parent 82f6d4f commit 6768d20
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 31 deletions.
20 changes: 12 additions & 8 deletions tests/roots/test-ext-collapse/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,28 @@ Collapsible directive tests

Collapsible sections can also have custom summary lines

.. collapse::
.. collapse:: Summary text here with **bold** and *em* and a :rfc:`2324`
reference! That was a newline in the reST source! We can also
have links_ and `more links <https://link2.example/>`__.

This is some body text!

.. collapse:: Collapsible section with no content.
:name: collapse-no-content
:class: spam

.. collapse:: Collapsible section with reStructuredText content:

Collapsible sections can have normal reST content such as **bold** and
*emphasised* text, and also links_!

.. _links: https://link.example/

.. collapse::
.. collapse:: Collapsible section with titles:

Collapsible sections can have sections:

A Section
---------

Some words within a section, as opposed to outwith the section.

.. collapse:: Summary text here with **bold** and *em* and a :rfc:`2324`
reference! That was a newline in the reST source! We can also
have links_ and `more links <https://link2.example/>`__.

This is some text!
73 changes: 50 additions & 23 deletions tests/test_extensions/test_ext_collapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@pytest.mark.sphinx('text', testroot='ext-collapse')
def test_non_html(app, status, warning):
app.build()
def test_non_html(app):
app.build(force_all=True)

# The content is inlined into the document:
assert (app.outdir / 'index.txt').read_text(encoding='utf8') == """\
Expand All @@ -23,12 +23,20 @@ def test_non_html(app, status, warning):
Collapsible sections can also have custom summary lines
Collapsed Content:
Summary text here with **bold** and *em* and a **RFC 2324** reference!
That was a newline in the reST source! We can also have links and more
links.
This is some body text!
Collapsible section with no content.
Collapsible section with reStructuredText content:
Collapsible sections can have normal reST content such as **bold** and
*emphasised* text, and also links!
Collapsed Content:
Collapsible section with titles:
Collapsible sections can have sections:
Expand All @@ -37,33 +45,52 @@ def test_non_html(app, status, warning):
=========
Some words within a section, as opposed to outwith the section.
"""

Summary text here with **bold** and *em* and a **RFC 2324** reference!
That was a newline in the reST source! We can also have links and more
links.

This is some text!
"""
@pytest.mark.sphinx('text', testroot='ext-collapse')
def test_non_html_post_transform(app):
app.build(force_all=True)
doctree = app.env.get_doctree('index')
app.env.apply_post_transforms(doctree, 'index')
assert list(doctree.findall(collapsible)) == []

collapsible_nodes = list(doctree.findall(nodes.container))
no_content = collapsible_nodes[3]
assert len(no_content) == 1
assert no_content[0].astext() == 'Collapsible section with no content.'


@pytest.mark.sphinx('html', testroot='ext-collapse')
def test_html(app, status, warning):
app.build()
def test_html(app):
app.build(force_all=True)
doctree = app.env.get_doctree('index')
app.env.apply_post_transforms(doctree, 'index')
collapsible_nodes = list(doctree.findall(collapsible))
assert len(collapsible_nodes) == 5

assert isinstance(collapsible_nodes[0][0], summary)
assert isinstance(collapsible_nodes[1][0], summary)
assert isinstance(collapsible_nodes[2][0], summary)
assert isinstance(collapsible_nodes[3][0], summary)
assert isinstance(collapsible_nodes[4][0], summary)
assert len(collapsible_nodes) == 6

default_summary = collapsible_nodes[0]
assert isinstance(default_summary[0], summary)
assert collapsible_nodes[0][0].astext() == 'Collapsed Content:'
assert collapsible_nodes[2][0].astext() == 'Collapsed Content:'
assert collapsible_nodes[3][0].astext() == 'Collapsed Content:'

assert isinstance(collapsible_nodes[3][2], nodes.section)
custom_summary = collapsible_nodes[1]
assert isinstance(custom_summary[0], summary)
assert custom_summary[0].astext() == 'Custom summary line for the collapsible content:'
assert custom_summary[1].astext() == 'Collapsible sections can also have custom summary lines'

rst_summary = collapsible_nodes[2]
assert isinstance(rst_summary[0], summary)
assert 'RFC 2324' in rst_summary[0].astext()
assert 'We can also\nhave ' in rst_summary[0][8] # type: ignore[operator]

no_content = collapsible_nodes[3]
assert isinstance(no_content[0], summary)
assert no_content[0].astext() == 'Collapsible section with no content.'
assert len(no_content) == 1

rst_content = collapsible_nodes[4]
assert isinstance(rst_content[0], summary)

assert 'RFC 2324' in collapsible_nodes[4][0].astext()
assert 'We can also\nhave ' in collapsible_nodes[4][0][8] # type: ignore[operator]
nested_titles = collapsible_nodes[5]
assert isinstance(nested_titles[0], summary)
assert isinstance(nested_titles[2], nodes.section)

0 comments on commit 6768d20

Please sign in to comment.