mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6038 from tk0miya/refactor_test_docutilsconf
refactor: test-docutilsconf
This commit is contained in:
commit
a844ce0f2f
@ -1,4 +0,0 @@
|
|||||||
project = 'Sphinx docutils conf <Tests>'
|
|
||||||
source_suffix = '.txt'
|
|
||||||
keep_warnings = True
|
|
||||||
exclude_patterns = ['_build']
|
|
6
tests/roots/test-docutilsconf/index.rst
Normal file
6
tests/roots/test-docutilsconf/index.rst
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
test-docutilsconf
|
||||||
|
==================
|
||||||
|
|
||||||
|
Sphinx [1]_
|
||||||
|
|
||||||
|
.. [1] Python Documentation Generator
|
@ -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
|
|
||||||
|
|
@ -8,88 +8,30 @@
|
|||||||
:license: BSD, see LICENSE for details.
|
:license: BSD, see LICENSE for details.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import re
|
|
||||||
|
|
||||||
import pytest
|
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
|
from sphinx.util.docutils import patch_docutils
|
||||||
|
|
||||||
|
|
||||||
def regex_count(expr, result):
|
@pytest.mark.sphinx('dummy', testroot='docutilsconf')
|
||||||
return len(re.findall(expr, result))
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf='')
|
|
||||||
def test_html_with_default_docutilsconf(app, status, warning):
|
def test_html_with_default_docutilsconf(app, status, warning):
|
||||||
with patch_docutils(app.confdir):
|
with patch_docutils(app.confdir):
|
||||||
app.builder.build(['contents'])
|
app.build()
|
||||||
|
|
||||||
result = (app.outdir / 'index.html').text()
|
doctree = app.env.get_doctree('index')
|
||||||
|
assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx ",
|
||||||
assert regex_count(r'<th class="field-name">', result) == 1
|
[nodes.footnote_reference, "1"])])
|
||||||
assert regex_count(r'<th class="field-name" colspan="2">', result) == 1
|
|
||||||
assert regex_count(r'<td class="option-group">', result) == 1
|
|
||||||
assert regex_count(r'<td class="option-group" colspan="2">', result) == 1
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf=(
|
@pytest.mark.sphinx('dummy', testroot='docutilsconf',
|
||||||
'\n[html4css1 writer]'
|
docutilsconf=('[restructuredtext parser]\n'
|
||||||
'\noption-limit:1'
|
'trim_footnote_reference_space: true\n'))
|
||||||
'\nfield-name-limit:1'
|
|
||||||
'\n')
|
|
||||||
)
|
|
||||||
def test_html_with_docutilsconf(app, status, warning):
|
def test_html_with_docutilsconf(app, status, warning):
|
||||||
with patch_docutils(app.confdir):
|
with patch_docutils(app.confdir):
|
||||||
app.builder.build(['contents'])
|
app.build()
|
||||||
|
|
||||||
result = (app.outdir / 'index.html').text()
|
doctree = app.env.get_doctree('index')
|
||||||
|
assert_node(doctree[0][1], [nodes.paragraph, ("Sphinx",
|
||||||
assert regex_count(r'<th class="field-name">', result) == 0
|
[nodes.footnote_reference, "1"])])
|
||||||
assert regex_count(r'<th class="field-name" colspan="2">', result) == 2
|
|
||||||
assert regex_count(r'<td class="option-group">', result) == 0
|
|
||||||
assert regex_count(r'<td class="option-group" colspan="2">', 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()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user