mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #1607: Sphinx crashes on building latexpdf with "howto" class
This commit is contained in:
parent
fa9fef3632
commit
0f1d8433e7
@ -526,5 +526,9 @@
|
||||
% Define literal-block environment
|
||||
\RequirePackage{float}
|
||||
\floatstyle{plaintop}
|
||||
\newfloat{literal-block}{htbp}{loc}[chapter]
|
||||
\ifx\thechapter\undefined
|
||||
\newfloat{literal-block}{htbp}{loc}[section]
|
||||
\else
|
||||
\newfloat{literal-block}{htbp}{loc}[chapter]
|
||||
\fi
|
||||
\floatname{literal-block}{List}
|
||||
|
@ -93,6 +93,71 @@ def test_latex(app, status, warning):
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
@with_app(buildername='latex',
|
||||
confoverrides={'latex_documents': [
|
||||
('contents', 'SphinxTests.tex', 'Sphinx Tests Documentation',
|
||||
'Georg Brandl \\and someone else', 'howto'),
|
||||
]},
|
||||
srcdir='latex_howto')
|
||||
def test_latex_howto(app, status, warning):
|
||||
LaTeXTranslator.ignore_missing_images = True
|
||||
app.builder.build_all()
|
||||
latex_warnings = warning.getvalue().replace(os.sep, '/')
|
||||
latex_warnings_exp = LATEX_WARNINGS % {
|
||||
'root': re.escape(app.srcdir.replace(os.sep, '/'))}
|
||||
assert re.match(latex_warnings_exp + '$', latex_warnings), \
|
||||
'Warnings don\'t match:\n' + \
|
||||
'--- Expected (regex):\n' + latex_warnings_exp + \
|
||||
'--- Got:\n' + latex_warnings
|
||||
|
||||
# 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:
|
||||
raise SkipTest('not running latex, it doesn\'t seem to be installed')
|
||||
for filename in ['fancyhdr.sty', 'fancybox.sty', 'titlesec.sty',
|
||||
'amsmath.sty', 'framed.sty', 'color.sty', 'fancyvrb.sty',
|
||||
'threeparttable.sty']:
|
||||
if not kpsetest(filename):
|
||||
raise SkipTest('not running latex, the %s package doesn\'t '
|
||||
'seem to be installed' % filename)
|
||||
|
||||
# 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:
|
||||
raise SkipTest # most likely pdflatex was not found
|
||||
else:
|
||||
stdout, stderr = p.communicate()
|
||||
if p.returncode != 0:
|
||||
print(stdout)
|
||||
print(stderr)
|
||||
app.cleanup()
|
||||
assert False, 'latex exited with return code %s' % p.returncode
|
||||
finally:
|
||||
os.chdir(cwd)
|
||||
|
||||
|
||||
@with_app(buildername='latex', testroot='numfig',
|
||||
confoverrides={'numfig': True})
|
||||
def test_numref(app, status, warning):
|
||||
|
@ -18,6 +18,7 @@ from six import StringIO
|
||||
from nose import tools, SkipTest
|
||||
|
||||
from sphinx import application
|
||||
from sphinx.builders.latex import LaTeXBuilder
|
||||
from sphinx.theming import Theme
|
||||
from sphinx.ext.autodoc import AutoDirective
|
||||
from sphinx.pycode import ModuleAnalyzer
|
||||
@ -203,6 +204,7 @@ class TestApp(application.Sphinx):
|
||||
Theme.themes.clear()
|
||||
AutoDirective._registry.clear()
|
||||
ModuleAnalyzer.cache.clear()
|
||||
LaTeXBuilder.usepackages = []
|
||||
sys.path[:] = self._saved_path
|
||||
sys.modules.pop('autodoc_fodder', None)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user