2010-01-17 05:29:00 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
test_build_latex
|
|
|
|
~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
Test the build process with LaTeX builder with the test root.
|
|
|
|
|
2014-03-01 01:18:16 -06:00
|
|
|
:copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
|
2010-01-17 05:29:00 -06:00
|
|
|
:license: BSD, see LICENSE for details.
|
|
|
|
"""
|
2014-01-19 04:17:10 -06:00
|
|
|
from __future__ import print_function
|
2010-01-17 05:29:00 -06:00
|
|
|
|
|
|
|
import os
|
2010-06-03 10:25:16 -05:00
|
|
|
import re
|
2010-01-17 05:29:00 -06:00
|
|
|
from subprocess import Popen, PIPE
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
from six import PY3
|
2014-04-28 21:46:47 -05:00
|
|
|
|
2010-01-17 05:29:00 -06:00
|
|
|
from sphinx.writers.latex import LaTeXTranslator
|
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
from util import SkipTest, remove_unicode_literals, with_app
|
2010-01-17 05:29:00 -06:00
|
|
|
from test_build_html import ENV_WARNINGS
|
|
|
|
|
|
|
|
|
|
|
|
LATEX_WARNINGS = ENV_WARNINGS + """\
|
2013-05-01 20:37:12 -05:00
|
|
|
None:None: WARNING: citation not found: missing
|
2010-06-03 10:25:16 -05:00
|
|
|
None:None: WARNING: no matching candidate for image URI u'foo.\\*'
|
2010-01-17 05:29:00 -06:00
|
|
|
WARNING: invalid pair index entry u''
|
2011-01-07 12:00:29 -06:00
|
|
|
WARNING: invalid pair index entry u'keyword; '
|
2010-01-17 05:29:00 -06:00
|
|
|
"""
|
|
|
|
|
2014-04-30 07:30:46 -05:00
|
|
|
if PY3:
|
2010-06-20 15:39:38 -05:00
|
|
|
LATEX_WARNINGS = remove_unicode_literals(LATEX_WARNINGS)
|
|
|
|
|
2010-01-17 05:29:00 -06:00
|
|
|
|
2014-09-21 10:17:02 -05:00
|
|
|
@with_app(buildername='latex', freshenv=True)
|
|
|
|
def test_latex(app, status, warning):
|
2010-01-17 05:29:00 -06:00
|
|
|
LaTeXTranslator.ignore_missing_images = True
|
|
|
|
app.builder.build_all()
|
2014-09-21 10:17:02 -05:00
|
|
|
latex_warnings = warning.getvalue().replace(os.sep, '/')
|
2012-05-01 22:05:41 -05:00
|
|
|
latex_warnings_exp = LATEX_WARNINGS % {
|
2014-09-21 10:17:02 -05:00
|
|
|
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
2010-06-03 10:25:16 -05:00
|
|
|
assert re.match(latex_warnings_exp + '$', latex_warnings), \
|
2014-09-21 10:17:02 -05:00
|
|
|
'Warnings don\'t match:\n' + \
|
|
|
|
'--- Expected (regex):\n' + latex_warnings_exp + \
|
|
|
|
'--- Got:\n' + latex_warnings
|
2010-07-27 12:07:51 -05:00
|
|
|
|
2010-01-17 05:29:00 -06:00
|
|
|
# file from latex_additional_files
|
|
|
|
assert (app.outdir / 'svgimg.svg').isfile()
|
|
|
|
|
|
|
|
# only run latex if all needed packages are there
|
|
|
|
def kpsetest(filename):
|
|
|
|
try:
|
|
|
|
p = Popen(['kpsewhich', filename], stdout=PIPE)
|
|
|
|
except OSError:
|
|
|
|
# no kpsewhich... either no tex distribution is installed or it is
|
|
|
|
# a "strange" one -- don't bother running latex
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
p.communicate()
|
|
|
|
if p.returncode != 0:
|
|
|
|
# not found
|
|
|
|
return False
|
|
|
|
# found
|
|
|
|
return True
|
|
|
|
|
|
|
|
if kpsetest('article.sty') is None:
|
2013-04-01 04:26:21 -05:00
|
|
|
raise SkipTest('not running latex, it doesn\'t seem to be installed')
|
2010-01-17 05:29:00 -06:00
|
|
|
for filename in ['fancyhdr.sty', 'fancybox.sty', 'titlesec.sty',
|
|
|
|
'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty',
|
|
|
|
'threeparttable.sty']:
|
|
|
|
if not kpsetest(filename):
|
2013-04-01 04:26:21 -05:00
|
|
|
raise SkipTest('not running latex, the %s package doesn\'t '
|
|
|
|
'seem to be installed' % filename)
|
2010-01-17 05:29:00 -06:00
|
|
|
|
|
|
|
# now, try to run latex over it
|
|
|
|
cwd = os.getcwd()
|
|
|
|
os.chdir(app.outdir)
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
p = Popen(['pdflatex', '--interaction=nonstopmode',
|
|
|
|
'SphinxTests.tex'], stdout=PIPE, stderr=PIPE)
|
|
|
|
except OSError:
|
2013-09-22 19:57:36 -05:00
|
|
|
raise SkipTest # most likely pdflatex was not found
|
2010-01-17 05:29:00 -06:00
|
|
|
else:
|
|
|
|
stdout, stderr = p.communicate()
|
|
|
|
if p.returncode != 0:
|
2014-01-19 04:17:10 -06:00
|
|
|
print(stdout)
|
|
|
|
print(stderr)
|
2010-01-17 05:29:00 -06:00
|
|
|
del app.cleanup_trees[:]
|
2010-02-20 07:21:03 -06:00
|
|
|
assert False, 'latex exited with return code %s' % p.returncode
|
2010-01-17 05:29:00 -06:00
|
|
|
finally:
|
|
|
|
os.chdir(cwd)
|