2010-09-16 02:19:06 -05:00
|
|
|
"""
|
|
|
|
|
test_build_texinfo
|
|
|
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
|
|
Test the build process with Texinfo builder with the test root.
|
|
|
|
|
|
2021-01-01 02:00:29 +09:00
|
|
|
:copyright: Copyright 2007-2021 by the Sphinx team, see AUTHORS.
|
2010-09-16 02:19:06 -05:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
import os
|
2010-10-22 10:17:35 +02:00
|
|
|
import re
|
2019-01-12 20:14:26 +09:00
|
|
|
import subprocess
|
2020-11-11 12:00:27 +01:00
|
|
|
from subprocess import PIPE, CalledProcessError
|
2019-02-03 19:33:28 +09:00
|
|
|
from unittest.mock import Mock
|
2010-09-16 02:19:06 -05:00
|
|
|
|
2017-01-06 01:14:47 +09:00
|
|
|
import pytest
|
2010-11-07 00:41:47 -05:00
|
|
|
|
2018-11-24 01:22:03 +09:00
|
|
|
from sphinx.builders.texinfo import default_texinfo_documents
|
|
|
|
|
from sphinx.config import Config
|
2018-09-08 10:52:24 +09:00
|
|
|
from sphinx.testing.util import strip_escseq
|
2019-02-03 18:41:07 +09:00
|
|
|
from sphinx.util.docutils import new_document
|
2018-02-19 22:39:14 +09:00
|
|
|
from sphinx.writers.texinfo import TexinfoTranslator
|
2010-09-16 02:19:06 -05:00
|
|
|
|
2020-11-20 19:04:26 +01:00
|
|
|
from .test_build_html import ENV_WARNINGS
|
|
|
|
|
|
2010-11-07 00:41:47 -05:00
|
|
|
TEXINFO_WARNINGS = ENV_WARNINGS + """\
|
2016-07-14 23:12:57 +09:00
|
|
|
%(root)s/index.rst:\\d+: WARNING: unknown option: &option
|
|
|
|
|
%(root)s/index.rst:\\d+: WARNING: citation not found: missing
|
2018-03-17 14:37:50 +09:00
|
|
|
%(root)s/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: foo.\\*
|
|
|
|
|
%(root)s/index.rst:\\d+: WARNING: a suitable image for texinfo builder not found: \
|
|
|
|
|
\\['application/pdf', 'image/svg\\+xml'\\] \\(svgimg.\\*\\)
|
2010-11-07 00:41:47 -05:00
|
|
|
"""
|
2010-10-22 10:17:35 +02:00
|
|
|
|
2010-09-16 02:19:06 -05:00
|
|
|
|
2017-01-06 01:14:47 +09:00
|
|
|
@pytest.mark.sphinx('texinfo', testroot='warnings', freshenv=True)
|
2016-07-14 23:12:57 +09:00
|
|
|
def test_texinfo_warnings(app, status, warning):
|
2010-09-16 02:19:06 -05:00
|
|
|
app.builder.build_all()
|
2017-05-01 16:19:53 -05:00
|
|
|
warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue()))
|
2016-07-14 23:12:57 +09:00
|
|
|
warnings_exp = TEXINFO_WARNINGS % {
|
2014-09-21 17:17:02 +02:00
|
|
|
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
2016-07-14 23:12:57 +09:00
|
|
|
assert re.match(warnings_exp + '$', warnings), \
|
2014-09-21 17:17:02 +02:00
|
|
|
'Warnings don\'t match:\n' + \
|
2016-07-14 23:12:57 +09:00
|
|
|
'--- Expected (regex):\n' + warnings_exp + \
|
|
|
|
|
'--- Got:\n' + warnings
|
|
|
|
|
|
|
|
|
|
|
2017-01-06 01:14:47 +09:00
|
|
|
@pytest.mark.sphinx('texinfo')
|
2016-07-14 23:12:57 +09:00
|
|
|
def test_texinfo(app, status, warning):
|
|
|
|
|
TexinfoTranslator.ignore_missing_images = True
|
|
|
|
|
app.builder.build_all()
|
2020-02-01 12:25:49 +09:00
|
|
|
result = (app.outdir / 'sphinxtests.texi').read_text()
|
2018-10-17 01:55:50 +09:00
|
|
|
assert ('@anchor{markup doc}@anchor{11}'
|
|
|
|
|
'@anchor{markup id1}@anchor{12}'
|
|
|
|
|
'@anchor{markup testing-various-markup}@anchor{13}' in result)
|
2018-12-09 00:35:46 +09:00
|
|
|
assert 'Footnotes' not in result
|
2010-09-16 02:19:06 -05:00
|
|
|
# now, try to run makeinfo over it
|
|
|
|
|
try:
|
2019-01-12 20:14:26 +09:00
|
|
|
args = ['makeinfo', '--no-split', 'sphinxtests.texi']
|
|
|
|
|
subprocess.run(args, stdout=PIPE, stderr=PIPE, cwd=app.outdir, check=True)
|
2020-06-14 00:46:19 +03:00
|
|
|
except OSError as exc:
|
|
|
|
|
raise pytest.skip.Exception from exc # most likely makeinfo was not found
|
2019-01-12 20:14:26 +09:00
|
|
|
except CalledProcessError as exc:
|
|
|
|
|
print(exc.stdout)
|
|
|
|
|
print(exc.stderr)
|
|
|
|
|
assert False, 'makeinfo exited with return code %s' % exc.retcode
|
2018-11-08 16:32:23 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('texinfo', testroot='markup-rubric')
|
|
|
|
|
def test_texinfo_rubric(app, status, warning):
|
|
|
|
|
app.build()
|
|
|
|
|
|
2020-02-01 11:58:51 +09:00
|
|
|
output = (app.outdir / 'python.texi').read_text()
|
2018-11-08 16:32:23 +09:00
|
|
|
assert '@heading This is a rubric' in output
|
|
|
|
|
assert '@heading This is a multiline rubric' in output
|
2018-11-08 23:32:54 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.sphinx('texinfo', testroot='markup-citation')
|
|
|
|
|
def test_texinfo_citation(app, status, warning):
|
|
|
|
|
app.builder.build_all()
|
|
|
|
|
|
2020-02-01 11:58:51 +09:00
|
|
|
output = (app.outdir / 'python.texi').read_text()
|
2018-11-08 23:32:54 +09:00
|
|
|
assert 'This is a citation ref; @ref{1,,[CITE1]} and @ref{2,,[CITE2]}.' in output
|
|
|
|
|
assert ('@anchor{index cite1}@anchor{1}@w{(CITE1)} \n'
|
|
|
|
|
'This is a citation\n') in output
|
|
|
|
|
assert ('@anchor{index cite2}@anchor{2}@w{(CITE2)} \n'
|
|
|
|
|
'This is a multiline citation\n') in output
|
2018-11-24 01:22:03 +09:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_default_texinfo_documents():
|
2019-01-02 22:20:22 +09:00
|
|
|
config = Config({'project': 'STASI™ Documentation',
|
2018-12-15 23:02:28 +09:00
|
|
|
'author': "Wolfgang Schäuble & G'Beckstein"})
|
2018-11-24 01:22:03 +09:00
|
|
|
config.init_values()
|
2018-12-15 23:02:28 +09:00
|
|
|
expected = [('index', 'stasi', 'STASI™ Documentation',
|
|
|
|
|
"Wolfgang Schäuble & G'Beckstein", 'stasi',
|
2018-11-24 01:22:03 +09:00
|
|
|
'One line description of project', 'Miscellaneous')]
|
|
|
|
|
assert default_texinfo_documents(config) == expected
|
2019-02-03 19:33:28 +09:00
|
|
|
|
|
|
|
|
|
2019-02-03 18:41:07 +09:00
|
|
|
@pytest.mark.sphinx('texinfo')
|
|
|
|
|
def test_texinfo_escape_id(app, status, warning):
|
|
|
|
|
settings = Mock(title='',
|
|
|
|
|
texinfo_dir_entry='',
|
|
|
|
|
texinfo_elements={})
|
|
|
|
|
document = new_document('', settings)
|
|
|
|
|
translator = app.builder.create_translator(document, app.builder)
|
|
|
|
|
|
|
|
|
|
assert translator.escape_id('Hello world') == 'Hello world'
|
|
|
|
|
assert translator.escape_id('Hello world') == 'Hello world'
|
|
|
|
|
assert translator.escape_id('Hello Sphinx world') == 'Hello Sphinx world'
|
|
|
|
|
assert translator.escape_id('Hello:world') == 'Hello world'
|
|
|
|
|
assert translator.escape_id('Hello(world)') == 'Hello world'
|
2019-02-03 18:51:19 +09:00
|
|
|
assert translator.escape_id('Hello world.') == 'Hello world'
|
2019-02-03 18:41:07 +09:00
|
|
|
assert translator.escape_id('.') == '.'
|