diff options
author | tk0miya <i.tkomiya@gmail.com> | 2014-11-24 12:13:17 +0900 |
---|---|---|
committer | tk0miya <i.tkomiya@gmail.com> | 2014-11-24 12:13:17 +0900 |
commit | 8febbfa76c0007c3bc796f9595d026197395d847 (patch) | |
tree | 0c80de3c0977493f15010fcd43f34349365be23f | |
parent | 48d8e201e4b548f2d23663652c49907ac3892619 (diff) | |
download | sphinx-8febbfa76c0007c3bc796f9595d026197395d847.tar.gz |
Fix #1607: Sphinx crashes on building latexpdf with "howto" class
-rw-r--r-- | sphinx/texinputs/sphinx.sty | 6 | ||||
-rw-r--r-- | tests/test_build_latex.py | 65 | ||||
-rw-r--r-- | tests/util.py | 2 |
3 files changed, 72 insertions, 1 deletions
diff --git a/sphinx/texinputs/sphinx.sty b/sphinx/texinputs/sphinx.sty index d617c62b..444b0373 100644 --- a/sphinx/texinputs/sphinx.sty +++ b/sphinx/texinputs/sphinx.sty @@ -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} diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 83b55caf..005f99af 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -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): diff --git a/tests/util.py b/tests/util.py index f2fbadd9..e184c28d 100644 --- a/tests/util.py +++ b/tests/util.py @@ -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) |