From 1d5e3cba0e2c50d71f28a24361373af1d58c7766 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 9 Feb 2019 00:36:25 +0900 Subject: [PATCH] refactor: test-docutilsconf Use options for reST parser instead of HTML4 writer's. --- tests/roots/test-docutilsconf/conf.py | 4 -- tests/roots/test-docutilsconf/index.rst | 6 ++ tests/roots/test-docutilsconf/index.txt | 15 ----- tests/test_docutilsconf.py | 86 ++++--------------------- 4 files changed, 20 insertions(+), 91 deletions(-) create mode 100644 tests/roots/test-docutilsconf/index.rst delete mode 100644 tests/roots/test-docutilsconf/index.txt diff --git a/tests/roots/test-docutilsconf/conf.py b/tests/roots/test-docutilsconf/conf.py index d7f27e6e1..e69de29bb 100644 --- a/tests/roots/test-docutilsconf/conf.py +++ b/tests/roots/test-docutilsconf/conf.py @@ -1,4 +0,0 @@ -project = 'Sphinx docutils conf ' -source_suffix = '.txt' -keep_warnings = True -exclude_patterns = ['_build'] diff --git a/tests/roots/test-docutilsconf/index.rst b/tests/roots/test-docutilsconf/index.rst new file mode 100644 index 000000000..d292e3227 --- /dev/null +++ b/tests/roots/test-docutilsconf/index.rst @@ -0,0 +1,6 @@ +test-docutilsconf +================== + +Sphinx [1]_ + +.. [1] Python Documentation Generator diff --git a/tests/roots/test-docutilsconf/index.txt b/tests/roots/test-docutilsconf/index.txt deleted file mode 100644 index b20204e61..000000000 --- a/tests/roots/test-docutilsconf/index.txt +++ /dev/null @@ -1,15 +0,0 @@ -docutils conf -============= - -field-name-limit ----------------- - -:short: desc -:long long long long: long title - -option-limit ------------- - ---short short desc ---long-long-long-long long desc - diff --git a/tests/test_docutilsconf.py b/tests/test_docutilsconf.py index 57ae785db..a8cfde7ef 100644 --- a/tests/test_docutilsconf.py +++ b/tests/test_docutilsconf.py @@ -8,88 +8,30 @@ :license: BSD, see LICENSE for details. """ -import re - import pytest +from docutils import nodes -from sphinx.testing.path import path +from sphinx.testing.util import assert_node from sphinx.util.docutils import patch_docutils -def regex_count(expr, result): - return len(re.findall(expr, result)) - - -@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf='') +@pytest.mark.sphinx('dummy', testroot='docutilsconf') def test_html_with_default_docutilsconf(app, status, warning): with patch_docutils(app.confdir): - app.builder.build(['contents']) + app.build() - result = (app.outdir / 'index.html').text() - - assert regex_count(r'', result) == 1 - assert regex_count(r'', result) == 1 - assert regex_count(r'', result) == 1 - assert regex_count(r'', result) == 1 + doctree = app.env.get_doctree('index') + assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx ", + [nodes.footnote_reference, "1"])]) -@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf=( - '\n[html4css1 writer]' - '\noption-limit:1' - '\nfield-name-limit:1' - '\n') -) +@pytest.mark.sphinx('dummy', testroot='docutilsconf', + docutilsconf=('[restructuredtext parser]\n' + 'trim_footnote_reference_space: true\n')) def test_html_with_docutilsconf(app, status, warning): with patch_docutils(app.confdir): - app.builder.build(['contents']) + app.build() - result = (app.outdir / 'index.html').text() - - assert regex_count(r'', result) == 0 - assert regex_count(r'', result) == 2 - assert regex_count(r'', result) == 0 - assert regex_count(r'', result) == 2 - - -@pytest.mark.sphinx('html', testroot='docutilsconf') -def test_html(app, status, warning): - with patch_docutils(app.confdir): - app.builder.build(['contents']) - assert warning.getvalue() == '' - - -@pytest.mark.sphinx('latex', testroot='docutilsconf') -def test_latex(app, status, warning): - with patch_docutils(app.confdir): - app.builder.build(['contents']) - assert warning.getvalue() == '' - - -@pytest.mark.sphinx('man', testroot='docutilsconf') -def test_man(app, status, warning): - with patch_docutils(app.confdir): - app.builder.build(['contents']) - assert warning.getvalue() == '' - - -@pytest.mark.sphinx('texinfo', testroot='docutilsconf') -def test_texinfo(app, status, warning): - with patch_docutils(app.confdir): - app.builder.build(['contents']) - - -@pytest.mark.sphinx('html', testroot='docutilsconf', - docutilsconf='[general]\nsource_link=true\n') -def test_docutils_source_link_with_nonascii_file(app, status, warning): - srcdir = path(app.srcdir) - mb_name = '\u65e5\u672c\u8a9e' - try: - (srcdir / (mb_name + '.txt')).write_text('') - except UnicodeEncodeError: - from sphinx.testing.path import FILESYSTEMENCODING - raise pytest.skip.Exception( - 'nonascii filename not supported on this filesystem encoding: ' - '%s', FILESYSTEMENCODING) - - with patch_docutils(app.confdir): - app.builder.build_all() + doctree = app.env.get_doctree('index') + assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx", + [nodes.footnote_reference, "1"])])