summaryrefslogtreecommitdiffstats
path: root/tests/test_directives/test_directive_patch.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_patch.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_patch.py')
-rw-r--r--tests/test_directives/test_directive_patch.py110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/test_directives/test_directive_patch.py b/tests/test_directives/test_directive_patch.py
new file mode 100644
index 0000000..f4eb8f9
--- /dev/null
+++ b/tests/test_directives/test_directive_patch.py
@@ -0,0 +1,110 @@
+"""Test the patched directives."""
+
+import pytest
+from docutils import nodes
+
+from sphinx.testing import restructuredtext
+from sphinx.testing.util import assert_node
+
+
+def test_code_directive(app):
+ # normal case
+ text = ('.. code::\n'
+ '\n'
+ ' print("hello world")\n')
+
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, nodes.literal_block, 'print("hello world")'])
+ assert_node(doctree[0], language="default", highlight_args={})
+
+ # with language
+ text = ('.. code:: python\n'
+ '\n'
+ ' print("hello world")\n')
+
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, nodes.literal_block, 'print("hello world")'])
+ assert_node(doctree[0], language="python", highlight_args={})
+
+ # :number-lines: option
+ text = ('.. code:: python\n'
+ ' :number-lines:\n'
+ '\n'
+ ' print("hello world")\n')
+
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, nodes.literal_block, 'print("hello world")'])
+ assert_node(doctree[0], language="python", linenos=True, highlight_args={})
+
+ # :number-lines: option
+ text = ('.. code:: python\n'
+ ' :number-lines: 5\n'
+ '\n'
+ ' print("hello world")\n')
+
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, nodes.literal_block, 'print("hello world")'])
+ assert_node(doctree[0], language="python", linenos=True, highlight_args={'linenostart': 5})
+
+
+@pytest.mark.sphinx(testroot='directive-csv-table')
+def test_csv_table_directive(app):
+ # relative path from current document
+ text = ('.. csv-table::\n'
+ ' :file: example.csv\n')
+ doctree = restructuredtext.parse(app, text, docname="subdir/index")
+ assert_node(doctree,
+ ([nodes.table, nodes.tgroup, (nodes.colspec,
+ nodes.colspec,
+ nodes.colspec,
+ [nodes.tbody, nodes.row])],))
+ assert_node(doctree[0][0][3][0],
+ ([nodes.entry, nodes.paragraph, "FOO"],
+ [nodes.entry, nodes.paragraph, "BAR"],
+ [nodes.entry, nodes.paragraph, "BAZ"]))
+
+ # absolute path from source directory
+ text = ('.. csv-table::\n'
+ ' :file: /example.csv\n')
+ doctree = restructuredtext.parse(app, text, docname="subdir/index")
+ assert_node(doctree,
+ ([nodes.table, nodes.tgroup, (nodes.colspec,
+ nodes.colspec,
+ nodes.colspec,
+ [nodes.tbody, nodes.row])],))
+ assert_node(doctree[0][0][3][0],
+ ([nodes.entry, nodes.paragraph, "foo"],
+ [nodes.entry, nodes.paragraph, "bar"],
+ [nodes.entry, nodes.paragraph, "baz"]))
+
+
+def test_math_directive(app):
+ # normal case
+ text = '.. math:: E = mc^2'
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, nodes.math_block, 'E = mc^2\n\n'])
+
+ # :name: option
+ text = ('.. math:: E = mc^2\n'
+ ' :name: eq1\n')
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, (nodes.target,
+ [nodes.math_block, "E = mc^2\n\n"])])
+ assert_node(doctree[1], nodes.math_block, docname='index', label="eq1", number=1)
+
+ # :label: option
+ text = ('.. math:: E = mc^2\n'
+ ' :label: eq2\n')
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, (nodes.target,
+ [nodes.math_block, 'E = mc^2\n\n'])])
+ assert_node(doctree[1], nodes.math_block, docname='index', label="eq2", number=2)
+
+ # :label: option without value
+ text = ('.. math:: E = mc^2\n'
+ ' :label:\n')
+ doctree = restructuredtext.parse(app, text)
+ assert_node(doctree, [nodes.document, (nodes.target,
+ [nodes.math_block, 'E = mc^2\n\n'])])
+ assert_node(doctree[1], nodes.math_block, ids=['equation-index-0'],
+ docname='index', label="index:0", number=3)