diff options
Diffstat (limited to 'tests/test_build_latex.py')
| -rw-r--r-- | tests/test_build_latex.py | 339 |
1 files changed, 193 insertions, 146 deletions
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index fb481371c..7acb1021f 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ test_build_latex ~~~~~~~~~~~~~~~~ @@ -8,22 +7,23 @@ :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS. :license: BSD, see LICENSE for details. """ -from __future__ import print_function import os import re +import subprocess from itertools import product from shutil import copyfile -from subprocess import Popen, PIPE +from subprocess import CalledProcessError, PIPE import pytest -from six import PY3 from test_build_html import ENV_WARNINGS +from sphinx.builders.latex import default_latex_documents +from sphinx.config import Config from sphinx.errors import SphinxError -from sphinx.testing.util import remove_unicode_literals, strip_escseq +from sphinx.testing.util import strip_escseq from sphinx.util import docutils -from sphinx.util.osutil import cd, ensuredir +from sphinx.util.osutil import ensuredir from sphinx.writers.latex import LaTeXTranslator @@ -40,51 +40,36 @@ LATEX_WARNINGS = ENV_WARNINGS + """\ %(root)s/index.rst:\\d+: WARNING: Could not lex literal_block as "c". Highlighting skipped. """ -if PY3: - LATEX_WARNINGS = remove_unicode_literals(LATEX_WARNINGS) - # only run latex if all needed packages are there def kpsetest(*filenames): try: - p = Popen(['kpsewhich'] + list(filenames), stdout=PIPE) - except OSError: - # no kpsewhich... either no tex distribution is installed or it is - # a "strange" one -- don't bother running latex - return False - else: - p.communicate() - if p.returncode != 0: - # not found - return False - # found + subprocess.run(['kpsewhich'] + list(filenames), stdout=PIPE, stderr=PIPE, check=True) return True + except (OSError, CalledProcessError): + return False # command not found or exit with non-zero # compile latex document with app.config.latex_engine -def compile_latex_document(app): +def compile_latex_document(app, filename='python.tex'): # now, try to run latex over it - with cd(app.outdir): - try: - ensuredir(app.config.latex_engine) - # keep a copy of latex file for this engine in case test fails - copyfile('SphinxTests.tex', - app.config.latex_engine + '/SphinxTests.tex') - p = Popen([app.config.latex_engine, - '--halt-on-error', - '--interaction=nonstopmode', - '-output-directory=%s' % app.config.latex_engine, - 'SphinxTests.tex'], - stdout=PIPE, stderr=PIPE) - except OSError: # most likely the latex executable was not found - raise pytest.skip.Exception - else: - stdout, stderr = p.communicate() - if p.returncode != 0: - print(stdout) - print(stderr) - assert False, '%s exited with return code %s' % ( - app.config.latex_engine, p.returncode) + try: + ensuredir(app.config.latex_engine) + # keep a copy of latex file for this engine in case test fails + copyfile(filename, app.config.latex_engine + '/' + filename) + args = [app.config.latex_engine, + '--halt-on-error', + '--interaction=nonstopmode', + '-output-directory=%s' % app.config.latex_engine, + filename] + subprocess.run(args, stdout=PIPE, stderr=PIPE, cwd=app.outdir, check=True) + except OSError: # most likely the latex executable was not found + raise pytest.skip.Exception + except CalledProcessError as exc: + print(exc.stdout) + print(exc.stderr) + assert False, '%s exited with return code %s' % (app.config.latex_engine, + exc.returncode) def skip_if_requested(testfunc): @@ -113,6 +98,7 @@ def skip_if_stylefiles_notfound(testfunc): def test_build_latex_doc(app, status, warning, engine, docclass): app.config.latex_engine = engine app.config.latex_documents[0] = app.config.latex_documents[0][:4] + (docclass,) + app.builder.init_context() LaTeXTranslator.ignore_missing_images = True app.builder.build_all() @@ -120,13 +106,13 @@ def test_build_latex_doc(app, status, warning, engine, docclass): # file from latex_additional_files assert (app.outdir / 'svgimg.svg').isfile() - compile_latex_document(app) + compile_latex_document(app, 'sphinxtests.tex') @pytest.mark.sphinx('latex') def test_writer(app, status, warning): app.builder.build_all() - result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') + result = (app.outdir / 'sphinxtests.tex').text(encoding='utf8') assert ('\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n' '\\noindent\\sphinxincludegraphics{{img}.png}\n' @@ -150,6 +136,8 @@ def test_writer(app, status, warning): '\\label{\\detokenize{markup:id11}}' '\\end{wrapfigure}' in result) + assert 'Footnotes' not in result + @pytest.mark.sphinx('latex', testroot='warnings', freshenv=True) def test_latex_warnings(app, status, warning): @@ -202,13 +190,10 @@ def test_latex_release(app, status, warning): confoverrides={'numfig': True}) def test_numref(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) - assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.\\@ }}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table }}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\literalblockname}{Listing}}' in result assert ('\\hyperref[\\detokenize{index:fig1}]' '{Fig.\\@ \\ref{\\detokenize{index:fig1}}}') in result assert ('\\hyperref[\\detokenize{baz:fig22}]' @@ -230,6 +215,13 @@ def test_numref(app, status, warning): assert ('\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' '\\nameref{\\detokenize{foo:foo}}}') in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result + assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Listing}}' in result + @pytest.mark.sphinx( 'latex', testroot='numfig', @@ -240,13 +232,10 @@ def test_numref(app, status, warning): 'section': 'SECTION-%s'}}) def test_numref_with_prefix1(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) - assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\literalblockname}{Code-}}' in result assert '\\ref{\\detokenize{index:fig1}}' in result assert '\\ref{\\detokenize{baz:fig22}}' in result assert '\\ref{\\detokenize{index:table-1}}' in result @@ -274,6 +263,13 @@ def test_numref_with_prefix1(app, status, warning): assert ('\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' '\\nameref{\\detokenize{foo:foo}}}') in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result + assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result + assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result + @pytest.mark.sphinx( 'latex', testroot='numfig', @@ -284,15 +280,10 @@ def test_numref_with_prefix1(app, status, warning): 'section': 'SECTION_%s_'}}) def test_numref_with_prefix2(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) - assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Figure:}}' in result - assert '\\def\\fnum@figure{\\figurename\\thefigure{}.}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Tab\\_}}' in result - assert '\\def\\fnum@table{\\tablename\\thetable{}:}' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\literalblockname}{Code-}}' in result assert ('\\hyperref[\\detokenize{index:fig1}]' '{Figure:\\ref{\\detokenize{index:fig1}}.\\@}') in result assert ('\\hyperref[\\detokenize{baz:fig22}]' @@ -314,40 +305,53 @@ def test_numref_with_prefix2(app, status, warning): assert ('\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' '\\nameref{\\detokenize{foo:foo}}}') in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result + assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result + assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result + assert r'\def\fnum@table{\tablename\thetable{}:}' in result + assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result + @pytest.mark.sphinx( 'latex', testroot='numfig', confoverrides={'numfig': True, 'language': 'ja'}) def test_numref_with_language_ja(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) - assert u'\\renewcommand{\\figurename}{\u56f3 }' in result # 図 - assert u'\\renewcommand{\\tablename}{\u8868 }' in result # 表 - assert u'\\renewcommand{\\literalblockname}{\u30ea\u30b9\u30c8}' in result # リスト - assert (u'\\hyperref[\\detokenize{index:fig1}]' - u'{\u56f3 \\ref{\\detokenize{index:fig1}}}') in result + assert ('\\hyperref[\\detokenize{index:fig1}]' + '{\u56f3 \\ref{\\detokenize{index:fig1}}}') in result assert ('\\hyperref[\\detokenize{baz:fig22}]' '{Figure\\ref{\\detokenize{baz:fig22}}}') in result - assert (u'\\hyperref[\\detokenize{index:table-1}]' - u'{\u8868 \\ref{\\detokenize{index:table-1}}}') in result + assert ('\\hyperref[\\detokenize{index:table-1}]' + '{\u8868 \\ref{\\detokenize{index:table-1}}}') in result assert ('\\hyperref[\\detokenize{baz:table22}]' '{Table:\\ref{\\detokenize{baz:table22}}}') in result - assert (u'\\hyperref[\\detokenize{index:code-1}]' - u'{\u30ea\u30b9\u30c8 \\ref{\\detokenize{index:code-1}}}') in result + assert ('\\hyperref[\\detokenize{index:code-1}]' + '{\u30ea\u30b9\u30c8 \\ref{\\detokenize{index:code-1}}}') in result assert ('\\hyperref[\\detokenize{baz:code22}]' '{Code-\\ref{\\detokenize{baz:code22}}}') in result - assert (u'\\hyperref[\\detokenize{foo:foo}]' - u'{\\ref{\\detokenize{foo:foo}} \u7ae0}') in result - assert (u'\\hyperref[\\detokenize{bar:bar-a}]' - u'{\\ref{\\detokenize{bar:bar-a}} \u7ae0}') in result + assert ('\\hyperref[\\detokenize{foo:foo}]' + '{\\ref{\\detokenize{foo:foo}} \u7ae0}') in result + assert ('\\hyperref[\\detokenize{bar:bar-a}]' + '{\\ref{\\detokenize{bar:bar-a}} \u7ae0}') in result assert ('\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} ' '\\nameref{\\detokenize{index:fig1}}}') in result assert ('\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' '\\nameref{\\detokenize{foo:foo}}}') in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result + assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result + assert '\\@iden{\\renewcommand{\\literalblockname}{リスト}}' in result + @pytest.mark.sphinx('latex', testroot='latex-numfig') def test_latex_obey_numfig_is_false(app, status, warning): @@ -399,12 +403,12 @@ def test_latex_obey_numfig_but_math_numfig_false(app, status, warning): assert '\\usepackage[,numfigreset=2]{sphinx}' in result -@pytest.mark.sphinx('latex') +@pytest.mark.sphinx('latex', testroot='basic') def test_latex_add_latex_package(app, status, warning): app.add_latex_package('foo') app.add_latex_package('bar', 'baz') app.builder.build_all() - result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') + result = (app.outdir / 'test.tex').text(encoding='utf8') assert '\\usepackage{foo}' in result assert '\\usepackage[baz]{bar}' in result @@ -412,7 +416,7 @@ def test_latex_add_latex_package(app, status, warning): @pytest.mark.sphinx('latex', testroot='latex-babel') def test_babel_with_no_language_settings(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -422,18 +426,22 @@ def test_babel_with_no_language_settings(app, status, warning): assert '\\usepackage[Bjarne]{fncychap}' in result assert ('\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result assert '\\shorthandoff' not in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{page}' in result + assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'de'}) def test_babel_with_language_de(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -443,18 +451,22 @@ def test_babel_with_language_de(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsngerman{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsngerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsngerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\addto\\extrasngerman{\\def\\pageautorefname{Seite}}\n' in result assert '\\shorthandoff{"}' in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{Seite}' in result + assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsngerman{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'ru'}) def test_babel_with_language_ru(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -464,19 +476,22 @@ def test_babel_with_language_ru(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsrussian{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsrussian{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsrussian{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert (u'\\addto\\extrasrussian{\\def\\pageautorefname' - u'{\u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0430}}\n' in result) assert '\\shorthandoff{"}' in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{страница}' in result + assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsrussian{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'tr'}) def test_babel_with_language_tr(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -486,18 +501,22 @@ def test_babel_with_language_tr(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsturkish{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsturkish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsturkish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\addto\\extrasturkish{\\def\\pageautorefname{sayfa}}\n' in result assert '\\shorthandoff{=}' in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{sayfa}' in result + assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsturkish{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'ja'}) def test_babel_with_language_ja(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -506,18 +525,22 @@ def test_babel_with_language_ja(app, status, warning): assert '\\usepackage{times}' in result assert '\\usepackage[Sonny]{fncychap}' not in result assert '\\renewcommand{\\contentsname}{Table of content}\n' in result - assert '\\renewcommand{\\figurename}{Fig.\\@ }\n' in result - assert '\\renewcommand{\\tablename}{Table.\\@ }\n' in result - assert u'\\def\\pageautorefname{ページ}\n' in result assert '\\shorthandoff' not in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{ページ}' in result + assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result + assert '\\@iden{\\renewcommand{\\tablename}{Table.\\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'unknown'}) def test_babel_with_unknown_language(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -527,20 +550,24 @@ def test_babel_with_unknown_language(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsenglish{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsenglish{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\addto\\extrasenglish{\\def\\pageautorefname{page}}\n' in result assert '\\shorthandoff' in result assert "WARNING: no Babel option known for language 'unknown'" in warning.getvalue() + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{page}' in result + assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'de', 'latex_engine': 'lualatex'}) def test_polyglossia_with_language_de(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -551,18 +578,22 @@ def test_polyglossia_with_language_de(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\def\\pageautorefname{Seite}\n' in result assert '\\shorthandoff' not in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{Seite}' in result + assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx( 'latex', testroot='latex-babel', confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'}) def test_polyglossia_with_language_de_1901(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -573,16 +604,20 @@ def test_polyglossia_with_language_de_1901(app, status, warning): assert '\\usepackage[Sonny]{fncychap}' in result assert ('\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n' in result) - assert '\\addto\\captionsgerman{\\renewcommand{\\figurename}{Fig.\\@ }}\n' in result - assert '\\addto\\captionsgerman{\\renewcommand{\\tablename}{Table.\\@ }}\n' in result - assert '\\def\\pageautorefname{page}\n' in result assert '\\shorthandoff' not in result + # sphinxmessages.sty + result = (app.outdir / 'sphinxmessages.sty').text(encoding='utf8') + print(result) + assert r'\def\pageautorefname{page}' in result + assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result + assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result + @pytest.mark.sphinx('latex') def test_footnote(app, status, warning): app.builder.build_all() - result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') + result = (app.outdir / 'sphinxtests.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -609,7 +644,7 @@ def test_footnote(app, status, warning): @pytest.mark.sphinx('latex', testroot='footnotes') def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -650,7 +685,7 @@ def test_reference_in_caption_and_codeblock_in_footnote(app, status, warning): confoverrides={'latex_show_urls': 'inline'}) def test_latex_show_urls_is_inline(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -695,7 +730,7 @@ def test_latex_show_urls_is_inline(app, status, warning): confoverrides={'latex_show_urls': 'footnote'}) def test_latex_show_urls_is_footnote(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -749,7 +784,7 @@ def test_latex_show_urls_is_footnote(app, status, warning): confoverrides={'latex_show_urls': 'no'}) def test_latex_show_urls_is_no(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -799,7 +834,7 @@ def test_latex_show_urls_footnote_and_substitutions(app, status, warning): @pytest.mark.sphinx('latex', testroot='image-in-section') def test_image_in_section(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -825,7 +860,7 @@ def test_latex_logo_if_not_found(app, status, warning): @pytest.mark.sphinx('latex', testroot='toctree-maxdepth') def test_toctree_maxdepth_manual(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -837,12 +872,12 @@ def test_toctree_maxdepth_manual(app, status, warning): @pytest.mark.sphinx( 'latex', testroot='toctree-maxdepth', confoverrides={'latex_documents': [ - ('index', 'SphinxTests.tex', 'Sphinx Tests Documentation', + ('index', 'python.tex', 'Sphinx Tests Documentation', 'Georg Brandl', 'howto'), ]}) def test_toctree_maxdepth_howto(app, status, warning): app.builder.build_all() - result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -856,7 +891,7 @@ def test_toctree_maxdepth_howto(app, status, warning): confoverrides={'master_doc': 'foo'}) def test_toctree_not_found(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -870,7 +905,7 @@ def test_toctree_not_found(app, status, warning): confoverrides={'master_doc': 'bar'}) def test_toctree_without_maxdepth(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -883,7 +918,7 @@ def test_toctree_without_maxdepth(app, status, warning): confoverrides={'master_doc': 'qux'}) def test_toctree_with_deeper_maxdepth(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -896,7 +931,7 @@ def test_toctree_with_deeper_maxdepth(app, status, warning): confoverrides={'latex_toplevel_sectioning': None}) def test_latex_toplevel_sectioning_is_None(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -908,7 +943,7 @@ def test_latex_toplevel_sectioning_is_None(app, status, warning): confoverrides={'latex_toplevel_sectioning': 'part'}) def test_latex_toplevel_sectioning_is_part(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -921,12 +956,12 @@ def test_latex_toplevel_sectioning_is_part(app, status, warning): 'latex', testroot='toctree-maxdepth', confoverrides={'latex_toplevel_sectioning': 'part', 'latex_documents': [ - ('index', 'Python.tex', 'Sphinx Tests Documentation', + ('index', 'python.tex', 'Sphinx Tests Documentation', 'Georg Brandl', 'howto') ]}) def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -940,7 +975,7 @@ def test_latex_toplevel_sectioning_is_part_with_howto(app, status, warning): confoverrides={'latex_toplevel_sectioning': 'chapter'}) def test_latex_toplevel_sectioning_is_chapter(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -951,12 +986,12 @@ def test_latex_toplevel_sectioning_is_chapter(app, status, warning): 'latex', testroot='toctree-maxdepth', confoverrides={'latex_toplevel_sectioning': 'chapter', 'latex_documents': [ - ('index', 'Python.tex', 'Sphinx Tests Documentation', + ('index', 'python.tex', 'Sphinx Tests Documentation', 'Georg Brandl', 'howto') ]}) def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -968,7 +1003,7 @@ def test_latex_toplevel_sectioning_is_chapter_with_howto(app, status, warning): confoverrides={'latex_toplevel_sectioning': 'section'}) def test_latex_toplevel_sectioning_is_section(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) @@ -979,11 +1014,11 @@ def test_latex_toplevel_sectioning_is_section(app, status, warning): @pytest.mark.sphinx('latex', testroot='maxlistdepth') def test_maxlistdepth_at_ten(app, status, warning): app.builder.build_all() - result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) print(status.getvalue()) print(warning.getvalue()) - compile_latex_document(app) + compile_latex_document(app, 'python.tex') @pytest.mark.skipif(docutils.__version_info__ < (0, 13), @@ -992,7 +1027,7 @@ def test_maxlistdepth_at_ten(app, status, warning): @pytest.mark.test_params(shared_result='latex-table') def test_latex_table_tabulars(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') tables = {} for chap in re.split(r'\\(?:section|chapter){', result)[1:]: sectname, content = chap.split('}', 1) @@ -1063,7 +1098,7 @@ def test_latex_table_tabulars(app, status, warning): @pytest.mark.test_params(shared_result='latex-table') def test_latex_table_longtable(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') tables = {} for chap in re.split(r'\\(?:section|chapter){', result)[1:]: sectname, content = chap.split('}', 1) @@ -1124,7 +1159,7 @@ def test_latex_table_longtable(app, status, warning): @pytest.mark.test_params(shared_result='latex-table') def test_latex_table_complex_tables(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') tables = {} for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]: sectname, content = chap.split('}', 1) @@ -1148,7 +1183,7 @@ def test_latex_table_complex_tables(app, status, warning): confoverrides={'templates_path': ['_mytemplates/latex']}) def test_latex_table_custom_template_caseA(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert 'SALUT LES COPAINS' in result @@ -1156,7 +1191,7 @@ def test_latex_table_custom_template_caseA(app, status, warning): confoverrides={'templates_path': ['_mytemplates']}) def test_latex_table_custom_template_caseB(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert 'SALUT LES COPAINS' not in result @@ -1164,14 +1199,14 @@ def test_latex_table_custom_template_caseB(app, status, warning): @pytest.mark.test_params(shared_result='latex-table') def test_latex_table_custom_template_caseC(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert 'SALUT LES COPAINS' not in result @pytest.mark.sphinx('latex', testroot='directives-raw') def test_latex_raw_directive(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') # standard case assert 'standalone raw directive (HTML)' not in result @@ -1187,7 +1222,7 @@ def test_latex_raw_directive(app, status, warning): def test_latex_remote_images(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert '\\sphinxincludegraphics{{python-logo}.png}' in result assert (app.outdir / 'python-logo.png').exists() assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result @@ -1199,7 +1234,7 @@ def test_latex_remote_images(app, status, warning): def test_latex_index(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert ('A \\index{famous@\\spxentry{famous}}famous ' '\\index{equation@\\spxentry{equation}}equation:\n' in result) assert ('\n\\index{Einstein@\\spxentry{Einstein}}' @@ -1213,7 +1248,7 @@ def test_latex_index(app, status, warning): def test_latex_equations(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') expected = (app.srcdir / 'expects' / 'latex-equations.tex').text().strip() assert expected in result @@ -1223,7 +1258,7 @@ def test_latex_equations(app, status, warning): def test_latex_image_in_parsed_literal(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}' '{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}' '}AFTER') in result @@ -1233,7 +1268,7 @@ def test_latex_image_in_parsed_literal(app, status, warning): def test_latex_nested_enumerated_list(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') assert ('\\def\\theenumi{\\arabic{enumi}}\n' '\\def\\labelenumi{\\theenumi .}\n' '\\makeatletter\\def\\p@enumii{\\p@enumi \\theenumi .}\\makeatother\n' @@ -1260,7 +1295,7 @@ def test_latex_nested_enumerated_list(app, status, warning): def test_latex_thebibliography(app, status, warning): app.builder.build_all() - result = (app.outdir / 'Python.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') print(result) assert ('\\begin{sphinxthebibliography}{AuthorYe}\n' '\\bibitem[AuthorYear]{index:authoryear}\n' @@ -1273,8 +1308,8 @@ def test_latex_thebibliography(app, status, warning): def test_latex_glossary(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') - assert (u'\\item[{änhlich\\index{änhlich@\\spxentry{änhlich}|spxpagem}' + result = (app.outdir / 'python.tex').text(encoding='utf8') + assert ('\\item[{änhlich\\index{änhlich@\\spxentry{änhlich}|spxpagem}' r'\phantomsection' r'\label{\detokenize{index:term-anhlich}}}] \leavevmode' in result) assert (r'\item[{boson\index{boson@\spxentry{boson}|spxpagem}\phantomsection' @@ -1289,7 +1324,7 @@ def test_latex_glossary(app, status, warning): r'\label{\detokenize{index:term-myon}}}] \leavevmode' r'\item[{electron\index{electron@\spxentry{electron}|spxpagem}\phantomsection' r'\label{\detokenize{index:term-electron}}}] \leavevmode' in result) - assert (u'\\item[{über\\index{über@\\spxentry{über}|spxpagem}\\phantomsection' + assert ('\\item[{über\\index{über@\\spxentry{über}|spxpagem}\\phantomsection' r'\label{\detokenize{index:term-uber}}}] \leavevmode' in result) @@ -1297,7 +1332,7 @@ def test_latex_glossary(app, status, warning): def test_latex_labels(app, status, warning): app.builder.build_all() - result = (app.outdir / 'test.tex').text(encoding='utf8') + result = (app.outdir / 'python.tex').text(encoding='utf8') # figures assert (r'\caption{labeled figure}' @@ -1336,3 +1371,15 @@ def test_latex_labels(app, status, warning): assert ('\\subsection{otherdoc}\n' r'\label{\detokenize{otherdoc:otherdoc}}' r'\label{\detokenize{otherdoc::doc}}' in result) + + +def test_default_latex_documents(): + from sphinx.util import texescape + texescape.init() + config = Config({'master_doc': 'index', + 'project': 'STASI™ Documentation', + 'author': "Wolfgang Schäuble & G'Beckstein."}) + config.init_values() + expected = [('index', 'stasi.tex', 'STASI™ Documentation', + r"Wolfgang Schäuble \& G'Beckstein.\@{}", 'manual')] + assert default_latex_documents(config) == expected |
