2013-07-27 00:13:15 -05:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_docutilsconf
|
|
|
|
~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test docutils.conf support for several writers.
|
|
|
|
|
2017-12-31 10:06:58 -06:00
|
|
|
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
|
2013-07-27 00:13:15 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import re
|
2017-06-14 13:26:15 -05:00
|
|
|
import sys
|
2014-09-21 10:17:02 -05:00
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
import pytest
|
2018-02-19 07:39:14 -06:00
|
|
|
|
2017-05-07 02:46:44 -05:00
|
|
|
from sphinx.testing.path import path
|
2018-03-29 08:45:20 -05:00
|
|
|
from sphinx.util.docutils import patch_docutils
|
2013-07-27 00:13:15 -05:00
|
|
|
|
|
|
|
|
|
|
|
def regex_count(expr, result):
|
|
|
|
return len(re.findall(expr, result))
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf='')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_html_with_default_docutilsconf(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
|
|
|
|
2013-07-27 00:13:15 -05:00
|
|
|
result = (app.outdir / 'contents.html').text(encoding='utf-8')
|
|
|
|
|
|
|
|
assert regex_count(r'<th class="field-name">', result) == 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
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='docutilsconf', freshenv=True, docutilsconf=(
|
2013-07-27 00:13:15 -05:00
|
|
|
'\n[html4css1 writer]'
|
|
|
|
'\noption-limit:1'
|
|
|
|
'\nfield-name-limit:1'
|
|
|
|
'\n')
|
|
|
|
)
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_html_with_docutilsconf(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
|
|
|
|
2013-07-27 00:13:15 -05:00
|
|
|
result = (app.outdir / 'contents.html').text(encoding='utf-8')
|
|
|
|
|
|
|
|
assert regex_count(r'<th class="field-name">', result) == 0
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='docutilsconf')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_html(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
2014-09-21 10:17:02 -05:00
|
|
|
assert warning.getvalue() == ''
|
2013-07-27 00:13:15 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('latex', testroot='docutilsconf')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_latex(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
2014-09-21 10:17:02 -05:00
|
|
|
assert warning.getvalue() == ''
|
2013-07-27 00:13:15 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('man', testroot='docutilsconf')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_man(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
2014-09-21 10:17:02 -05:00
|
|
|
assert warning.getvalue() == ''
|
2013-07-27 00:13:15 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('texinfo', testroot='docutilsconf')
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_texinfo(app, status, warning):
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build(['contents'])
|
2014-08-11 10:11:23 -05:00
|
|
|
|
|
|
|
|
2017-01-05 10:14:47 -06:00
|
|
|
@pytest.mark.sphinx('html', testroot='docutilsconf',
|
|
|
|
docutilsconf='[general]\nsource_link=true\n')
|
2017-12-23 06:20:32 -06:00
|
|
|
@pytest.mark.skip(sys.platform == "win32" and
|
2017-06-14 13:26:15 -05:00
|
|
|
not (sys.version_info.major >= 3 and sys.version_info.minor >= 2),
|
|
|
|
reason="Python < 3.2 on Win32 doesn't handle non-ASCII paths right")
|
2014-09-21 10:17:02 -05:00
|
|
|
def test_docutils_source_link_with_nonascii_file(app, status, warning):
|
2014-08-11 10:11:23 -05:00
|
|
|
srcdir = path(app.srcdir)
|
|
|
|
mb_name = u'\u65e5\u672c\u8a9e'
|
|
|
|
try:
|
|
|
|
(srcdir / (mb_name + '.txt')).write_text('')
|
|
|
|
except UnicodeEncodeError:
|
2017-05-07 02:46:44 -05:00
|
|
|
from sphinx.testing.path import FILESYSTEMENCODING
|
2017-04-27 09:38:42 -05:00
|
|
|
raise pytest.skip.Exception(
|
2014-08-11 10:11:23 -05:00
|
|
|
'nonascii filename not supported on this filesystem encoding: '
|
|
|
|
'%s', FILESYSTEMENCODING)
|
|
|
|
|
2018-03-29 08:45:20 -05:00
|
|
|
with patch_docutils(app.confdir):
|
|
|
|
app.builder.build_all()
|