diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-10 12:23:15 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-10 12:23:15 +0900 |
commit | a37e508b3fc7b28cf10bbd51b766ce62fc390c4c (patch) | |
tree | a75e561df3cd8b8fb96923f74ddd62e12bbc9f57 /tests | |
parent | 2606002bb4d0470181460740b608d13d03b84bfe (diff) | |
parent | 63c05f2b6d7c5408978bafe8238913d4dd6637b2 (diff) | |
download | sphinx-git-a37e508b3fc7b28cf10bbd51b766ce62fc390c4c.tar.gz |
Merge branch '2.0'
Diffstat (limited to 'tests')
-rw-r--r-- | tests/test_directive_other.py | 31 | ||||
-rw-r--r-- | tests/test_directive_patch.py | 54 |
2 files changed, 63 insertions, 22 deletions
diff --git a/tests/test_directive_other.py b/tests/test_directive_other.py index cbbebee5c..376b9cd69 100644 --- a/tests/test_directive_other.py +++ b/tests/test_directive_other.py @@ -10,25 +10,12 @@ import pytest from docutils import nodes -from docutils.core import publish_doctree from sphinx import addnodes -from sphinx.io import SphinxStandaloneReader -from sphinx.parsers import RSTParser +from sphinx.testing import restructuredtext from sphinx.testing.util import assert_node -def parse(app, docname, text): - app.env.temp_data['docname'] = docname - parser = RSTParser() - parser.set_application(app) - return publish_doctree(text, app.srcdir / docname + '.rst', - reader=SphinxStandaloneReader(app), - parser=parser, - settings_overrides={'env': app.env, - 'gettext_compact': True}) - - @pytest.mark.sphinx(testroot='toctree-glob') def test_toctree(app): text = (".. toctree::\n" @@ -38,7 +25,7 @@ def test_toctree(app): " baz\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'foo'), (None, 'bar/index'), (None, 'baz')], @@ -55,7 +42,7 @@ def test_relative_toctree(app): " ../quux\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'bar/index', text) + doctree = restructuredtext.parse(app, text, 'bar/index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'bar/bar_1'), (None, 'bar/bar_2'), (None, 'bar/bar_3'), @@ -72,7 +59,7 @@ def test_toctree_urls_and_titles(app): " The BAR <bar/index>\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[('Sphinx', 'https://www.sphinx-doc.org/'), @@ -89,7 +76,7 @@ def test_toctree_glob(app): " *\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'baz'), (None, 'foo'), (None, 'quux')], @@ -103,7 +90,7 @@ def test_toctree_glob(app): " *\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'foo'), (None, 'baz'), (None, 'quux')], @@ -117,7 +104,7 @@ def test_toctree_glob(app): " foo\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'baz'), (None, 'foo'), (None, 'quux'), (None, 'foo')], @@ -132,7 +119,7 @@ def test_toctree_glob_and_url(app): " https://example.com/?q=sphinx\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'https://example.com/?q=sphinx')], @@ -147,7 +134,7 @@ def test_toctree_twice(app): " foo\n") app.env.find_files(app.config, app.builder) - doctree = parse(app, 'index', text) + doctree = restructuredtext.parse(app, text, 'index') assert_node(doctree, [nodes.document, nodes.compound, addnodes.toctree]) assert_node(doctree[0][0], entries=[(None, 'foo'), (None, 'foo')], diff --git a/tests/test_directive_patch.py b/tests/test_directive_patch.py new file mode 100644 index 000000000..4f61f2d0b --- /dev/null +++ b/tests/test_directive_patch.py @@ -0,0 +1,54 @@ +""" + test_directive_patch + ~~~~~~~~~~~~~~~~~~~ + + Test the patched directives. + + :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +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}) |