sphinx/tests/test_build_texinfo.py

92 lines
3.1 KiB
Python
Raw Normal View History

2010-09-16 02:19:06 -05:00
# -*- coding: utf-8 -*-
"""
test_build_texinfo
~~~~~~~~~~~~~~~~~~
Test the build process with Texinfo builder with the test root.
2017-12-31 10:06:58 -06:00
:copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
2010-09-16 02:19:06 -05:00
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
2010-09-16 02:19:06 -05:00
import os
import re
2010-09-16 02:19:06 -05:00
from subprocess import Popen, PIPE
import pytest
2018-02-19 07:39:14 -06:00
from test_build_html import ENV_WARNINGS
2018-09-07 20:52:24 -05:00
from sphinx.testing.util import strip_escseq
2018-02-19 07:39:14 -06:00
from sphinx.writers.texinfo import TexinfoTranslator
2010-09-16 02:19:06 -05:00
TEXINFO_WARNINGS = ENV_WARNINGS + """\
2016-07-14 09:12:57 -05:00
%(root)s/index.rst:\\d+: WARNING: unknown option: &option
%(root)s/index.rst:\\d+: WARNING: citation not found: missing
%(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-09-16 02:19:06 -05:00
@pytest.mark.sphinx('texinfo', testroot='warnings', freshenv=True)
2016-07-14 09:12:57 -05:00
def test_texinfo_warnings(app, status, warning):
2010-09-16 02:19:06 -05:00
app.builder.build_all()
warnings = strip_escseq(re.sub(re.escape(os.sep) + '{1,2}', '/', warning.getvalue()))
2016-07-14 09:12:57 -05:00
warnings_exp = TEXINFO_WARNINGS % {
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
2016-07-14 09:12:57 -05:00
assert re.match(warnings_exp + '$', warnings), \
'Warnings don\'t match:\n' + \
2016-07-14 09:12:57 -05:00
'--- Expected (regex):\n' + warnings_exp + \
'--- Got:\n' + warnings
@pytest.mark.sphinx('texinfo')
2016-07-14 09:12:57 -05:00
def test_texinfo(app, status, warning):
TexinfoTranslator.ignore_missing_images = True
app.builder.build_all()
result = (app.outdir / 'sphinxtests.texi').text(encoding='utf8')
assert ('@anchor{markup doc}@anchor{11}'
'@anchor{markup id1}@anchor{12}'
'@anchor{markup testing-various-markup}@anchor{13}' in result)
2010-09-16 02:19:06 -05:00
# now, try to run makeinfo over it
cwd = os.getcwd()
os.chdir(app.outdir)
try:
try:
p = Popen(['makeinfo', '--no-split', 'sphinxtests.texi'],
2010-09-16 02:19:06 -05:00
stdout=PIPE, stderr=PIPE)
except OSError:
2017-04-27 09:38:42 -05:00
raise pytest.skip.Exception # most likely makeinfo was not found
2010-09-16 02:19:06 -05:00
else:
stdout, stderr = p.communicate()
retcode = p.returncode
if retcode != 0:
print(stdout)
print(stderr)
2010-09-16 02:19:06 -05:00
assert False, 'makeinfo exited with return code %s' % retcode
finally:
os.chdir(cwd)
@pytest.mark.sphinx('texinfo', testroot='markup-rubric')
def test_texinfo_rubric(app, status, warning):
app.build()
output = (app.outdir / 'python.texi').text()
assert '@heading This is a rubric' in output
assert '@heading This is a multiline rubric' in output
@pytest.mark.sphinx('texinfo', testroot='markup-citation')
def test_texinfo_citation(app, status, warning):
app.builder.build_all()
output = (app.outdir / 'python.texi').text()
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