summaryrefslogtreecommitdiffstats
path: root/tests/test_directives/test_directive_object_description.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-05 16:20:58 +0000
commit5bb0bb4be543fd5eca41673696a62ed80d493591 (patch)
treead2c464f140e86c7f178a6276d7ea4a93e3e6c92 /tests/test_directives/test_directive_object_description.py
parentAdding upstream version 7.2.6. (diff)
downloadsphinx-upstream/7.3.7.tar.xz
sphinx-upstream/7.3.7.zip
Adding upstream version 7.3.7.upstream/7.3.7
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_directives/test_directive_object_description.py')
-rw-r--r--tests/test_directives/test_directive_object_description.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/tests/test_directives/test_directive_object_description.py b/tests/test_directives/test_directive_object_description.py
new file mode 100644
index 0000000..f2c9f9d
--- /dev/null
+++ b/tests/test_directives/test_directive_object_description.py
@@ -0,0 +1,59 @@
+"""Test object description directives."""
+
+import docutils.utils
+import pytest
+from docutils import nodes
+
+from sphinx import addnodes
+from sphinx.io import create_publisher
+from sphinx.testing import restructuredtext
+from sphinx.util.docutils import sphinx_domains
+
+
+def _doctree_for_test(builder, docname: str) -> nodes.document:
+ builder.env.prepare_settings(docname)
+ publisher = create_publisher(builder.app, 'restructuredtext')
+ with sphinx_domains(builder.env):
+ publisher.set_source(source_path=builder.env.doc2path(docname))
+ publisher.publish()
+ return publisher.document
+
+
+@pytest.mark.sphinx('text', testroot='object-description-sections')
+def test_object_description_sections(app):
+ doctree = _doctree_for_test(app.builder, 'index')
+ # <document>
+ # <index>
+ # <desc>
+ # <desc_signature>
+ # <desc_name>
+ # func
+ # <desc_parameterlist>
+ # <desc_content>
+ # <section>
+ # <title>
+ # Overview
+ # <paragraph>
+ # Lorem ipsum dolar sit amet
+
+ assert isinstance(doctree[0], addnodes.index)
+ assert isinstance(doctree[1], addnodes.desc)
+ assert isinstance(doctree[1][0], addnodes.desc_signature)
+ assert isinstance(doctree[1][1], addnodes.desc_content)
+ assert isinstance(doctree[1][1][0], nodes.section)
+ assert isinstance(doctree[1][1][0][0], nodes.title)
+ assert doctree[1][1][0][0][0] == 'Overview'
+ assert isinstance(doctree[1][1][0][1], nodes.paragraph)
+ assert doctree[1][1][0][1][0] == 'Lorem ipsum dolar sit amet'
+
+
+def test_object_description_content_line_number(app):
+ text = (".. py:function:: foo(bar)\n" +
+ "\n" +
+ " Some link here: :ref:`abc`\n")
+ doc = restructuredtext.parse(app, text)
+ xrefs = list(doc.findall(condition=addnodes.pending_xref))
+ assert len(xrefs) == 1
+ source, line = docutils.utils.get_source_line(xrefs[0])
+ assert 'index.rst' in source
+ assert line == 3