diff options
Diffstat (limited to 'tests/test_build_latex.py')
-rw-r--r-- | tests/test_build_latex.py | 127 |
1 files changed, 70 insertions, 57 deletions
diff --git a/tests/test_build_latex.py b/tests/test_build_latex.py index 60ea0b480..8922e3491 100644 --- a/tests/test_build_latex.py +++ b/tests/test_build_latex.py @@ -17,6 +17,8 @@ from subprocess import Popen, PIPE import pytest 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 strip_escseq from sphinx.util import docutils @@ -56,19 +58,18 @@ def kpsetest(*filenames): # 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') + copyfile(filename, app.config.latex_engine + '/' + filename) p = Popen([app.config.latex_engine, '--halt-on-error', '--interaction=nonstopmode', '-output-directory=%s' % app.config.latex_engine, - 'SphinxTests.tex'], + filename], stdout=PIPE, stderr=PIPE) except OSError: # most likely the latex executable was not found raise pytest.skip.Exception @@ -115,13 +116,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' @@ -199,7 +200,7 @@ 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()) @@ -241,7 +242,7 @@ 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()) @@ -289,7 +290,7 @@ 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()) @@ -329,7 +330,7 @@ def test_numref_with_prefix2(app, status, warning): 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()) @@ -412,12 +413,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 @@ -425,7 +426,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()) @@ -450,7 +451,7 @@ def test_babel_with_no_language_settings(app, status, warning): 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()) @@ -475,7 +476,7 @@ def test_babel_with_language_de(app, status, warning): 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()) @@ -500,7 +501,7 @@ def test_babel_with_language_ru(app, status, warning): 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()) @@ -525,7 +526,7 @@ def test_babel_with_language_tr(app, status, warning): 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()) @@ -549,7 +550,7 @@ def test_babel_with_language_ja(app, status, warning): 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()) @@ -576,7 +577,7 @@ def test_babel_with_unknown_language(app, status, warning): 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()) @@ -602,7 +603,7 @@ def test_polyglossia_with_language_de(app, status, warning): 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()) @@ -626,7 +627,7 @@ def test_polyglossia_with_language_de_1901(app, status, warning): @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()) @@ -653,7 +654,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()) @@ -694,7 +695,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()) @@ -739,7 +740,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()) @@ -793,7 +794,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()) @@ -843,7 +844,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()) @@ -869,7 +870,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()) @@ -881,12 +882,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()) @@ -900,7 +901,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()) @@ -914,7 +915,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()) @@ -927,7 +928,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()) @@ -940,7 +941,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()) @@ -952,7 +953,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()) @@ -965,12 +966,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()) @@ -984,7 +985,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()) @@ -995,12 +996,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()) @@ -1012,7 +1013,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()) @@ -1023,11 +1024,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), @@ -1036,7 +1037,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) @@ -1107,7 +1108,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) @@ -1168,7 +1169,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) @@ -1192,7 +1193,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 @@ -1200,7 +1201,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 @@ -1208,14 +1209,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 @@ -1231,7 +1232,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 @@ -1243,7 +1244,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}}' @@ -1257,7 +1258,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 @@ -1267,7 +1268,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}' '{\\scalebox{2.000000}{\\sphinxincludegraphics[height=1cm]{{pic}.png}}}' '}AFTER') in result @@ -1277,7 +1278,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' @@ -1304,7 +1305,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' @@ -1317,7 +1318,7 @@ 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') + 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) @@ -1341,7 +1342,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}' @@ -1380,3 +1381,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': u'STASI™ Documentation', + 'author': u"Wolfgang Schäuble & G'Beckstein"}) + config.init_values() + expected = [('index', 'stasi.tex', u'STASI™ Documentation', + u"Wolfgang Schäuble \\& G'Beckstein", 'manual')] + assert default_latex_documents(config) == expected |