mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Add failing tests for nested sections in only directives.
This commit is contained in:
parent
14d738c455
commit
c5405184ba
@ -27,6 +27,7 @@ Contents:
|
||||
doctest
|
||||
extensions
|
||||
versioning/index
|
||||
only
|
||||
|
||||
Python <http://python.org/>
|
||||
|
||||
|
203
tests/root/only.txt
Normal file
203
tests/root/only.txt
Normal file
@ -0,0 +1,203 @@
|
||||
|
||||
1. Sections in only directives
|
||||
==============================
|
||||
|
||||
Testing sections in only directives.
|
||||
|
||||
.. only:: nonexisting_tag
|
||||
|
||||
Skipped Section
|
||||
---------------
|
||||
Should not be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.1. Section
|
||||
------------
|
||||
Should be here.
|
||||
|
||||
1.2. Section
|
||||
------------
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.2.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
.. only:: nonexisting_tag
|
||||
|
||||
Skipped Subsection
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
Should not be here.
|
||||
|
||||
1.3. Section
|
||||
------------
|
||||
|
||||
1.3.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.4. Section
|
||||
------------
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.4.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.5. Section
|
||||
------------
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.5.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.5.2. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.6. Section
|
||||
------------
|
||||
|
||||
1.6.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.6.2. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.6.3. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.7. Section
|
||||
------------
|
||||
|
||||
1.7.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.7.1.1. Subsubsection
|
||||
......................
|
||||
Should be here.
|
||||
|
||||
1.8. Section
|
||||
------------
|
||||
|
||||
1.8.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.8.1.1. Subsubsection
|
||||
......................
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.8.1.2. Subsubsection
|
||||
......................
|
||||
Should be here.
|
||||
|
||||
1.9. Section
|
||||
------------
|
||||
|
||||
.. only:: nonexisting_tag
|
||||
|
||||
Skipped Subsection
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
|
||||
1.9.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.9.1.1. Subsubsection
|
||||
......................
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.10. Section
|
||||
-------------
|
||||
Should be here.
|
||||
|
||||
1.11. Section
|
||||
-------------
|
||||
|
||||
Text before subsection 11.1.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
More text before subsection 11.1.
|
||||
|
||||
1.11.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
Text after subsection 11.1.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.12. Section
|
||||
-------------
|
||||
Should be here.
|
||||
|
||||
1.12.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.13. Section
|
||||
-------------
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.14. Section
|
||||
-------------
|
||||
Should be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
1.14.1. Subsection
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
Should be here.
|
||||
|
||||
1.15. Section
|
||||
-------------
|
||||
Should be here.
|
||||
|
||||
.. only:: nonexisting_tag
|
||||
|
||||
Skipped document level heading
|
||||
==============================
|
||||
Should not be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
2. Included document level heading
|
||||
==================================
|
||||
Should be here.
|
||||
|
||||
3. Document level heading
|
||||
=========================
|
||||
Should be here.
|
||||
|
||||
.. only:: nonexisting_tag
|
||||
|
||||
Skipped document level heading
|
||||
==============================
|
||||
Should not be here.
|
||||
|
||||
.. only:: not nonexisting_tag
|
||||
|
||||
4. Another included document level heading
|
||||
==========================================
|
||||
Should be here.
|
63
tests/test_only_directive.py
Normal file
63
tests/test_only_directive.py
Normal file
@ -0,0 +1,63 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
test_only_directive
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Test the only directive with the test root.
|
||||
|
||||
:copyright: Copyright 2010 by the Sphinx team, see AUTHORS.
|
||||
:license: BSD, see LICENSE for details.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
from docutils import nodes
|
||||
|
||||
from util import *
|
||||
|
||||
|
||||
def teardown_module():
|
||||
(test_root / '_build').rmtree(True)
|
||||
|
||||
|
||||
@with_app(buildername='text')
|
||||
def test_sectioning(app):
|
||||
|
||||
def getsects(section):
|
||||
if not isinstance(section, nodes.section):
|
||||
return [getsects(n) for n in section.children]
|
||||
title = section.next_node(nodes.title).astext().strip()
|
||||
subsects = []
|
||||
children = section.children[:]
|
||||
while children:
|
||||
node = children.pop(0)
|
||||
if isinstance(node, nodes.section):
|
||||
subsects.append(node)
|
||||
continue
|
||||
children = list(node.children) + children
|
||||
return [title, [getsects(subsect) for subsect in subsects]]
|
||||
|
||||
def testsects(prefix, sects, indent=0):
|
||||
title = sects[0]
|
||||
sprint(' ' * indent + title)
|
||||
parent_num = title.split()[0]
|
||||
assert prefix == parent_num, \
|
||||
'Section out of place: %r' % title
|
||||
for i, subsect in enumerate(sects[1]):
|
||||
num = subsect[0].split()[0]
|
||||
assert re.match('[0-9]+[.0-9]*[.]', num), \
|
||||
'Unnumbered section: %r' % subsect[0]
|
||||
testsects(prefix + str(i+1) + '.', subsect, indent+4)
|
||||
|
||||
app.builder.build(['only'])
|
||||
doctree = app.env.get_doctree('only')
|
||||
app.env.process_only_nodes(doctree, app.builder)
|
||||
|
||||
parts = [getsects(n)
|
||||
for n in filter(lambda n: isinstance(n, nodes.section),
|
||||
doctree.children)]
|
||||
sprint('\nChecking headings in only.txt:')
|
||||
for i, s in enumerate(parts):
|
||||
testsects(str(i+1) + '.', s, 4)
|
||||
assert len(parts) == 4, 'Expected 4 document level headings, got:\n%s' % \
|
||||
'\n'.join([p[0] for p in parts])
|
Loading…
Reference in New Issue
Block a user