summaryrefslogtreecommitdiffstats
path: root/tests/test_directive_only.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 17:25:40 +0000
commitcf7da1843c45a4c2df7a749f7886a2d2ba0ee92a (patch)
tree18dcde1a8d1f5570a77cd0c361de3b490d02c789 /tests/test_directive_only.py
parentInitial commit. (diff)
downloadsphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.tar.xz
sphinx-cf7da1843c45a4c2df7a749f7886a2d2ba0ee92a.zip
Adding upstream version 7.2.6.upstream/7.2.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_directive_only.py')
-rw-r--r--tests/test_directive_only.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/test_directive_only.py b/tests/test_directive_only.py
new file mode 100644
index 0000000..2e9ea63
--- /dev/null
+++ b/tests/test_directive_only.py
@@ -0,0 +1,46 @@
+"""Test the only directive with the test root."""
+
+import re
+
+import pytest
+from docutils import nodes
+
+
+@pytest.mark.sphinx('text', testroot='directive-only')
+def test_sectioning(app, status, warning):
+
+ 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]
+ 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.apply_post_transforms(doctree, 'only')
+
+ parts = [getsects(n)
+ for n in [_n for _n in doctree.children if isinstance(_n, nodes.section)]]
+ 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])