| 1 |
"""Test the build process with LaTeX builder with the test root.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import http.server |
| 6 |
import os |
| 7 |
import re |
| 8 |
import subprocess |
| 9 |
from contextlib import chdir |
| 10 |
from pathlib import Path |
| 11 |
from shutil import copyfile |
| 12 |
from subprocess import CalledProcessError |
| 13 |
from types import NoneType |
| 14 |
from typing import TYPE_CHECKING |
| 15 |
|
| 16 |
import docutils |
| 17 |
import pygments |
| 18 |
import pytest |
| 19 |
|
| 20 |
from sphinx.builders.latex import default_latex_documents |
| 21 |
from sphinx.config import Config |
| 22 |
from sphinx.errors import SphinxError |
| 23 |
from sphinx.ext.intersphinx import setup as intersphinx_setup |
| 24 |
from sphinx.ext.intersphinx._load import load_mappings, validate_intersphinx_mapping |
| 25 |
from sphinx.util.osutil import ensuredir |
| 26 |
from sphinx.writers.latex import LaTeXTranslator |
| 27 |
|
| 28 |
from tests.utils import TEST_ROOTS_DIR, http_server |
| 29 |
|
| 30 |
if TYPE_CHECKING: |
| 31 |
from sphinx.testing.util import SphinxTestApp |
| 32 |
|
| 33 |
STYLEFILES = [ |
| 34 |
'article.cls', |
| 35 |
'fancyhdr.sty', |
| 36 |
'titlesec.sty', |
| 37 |
'amsmath.sty', |
| 38 |
'framed.sty', |
| 39 |
'color.sty', |
| 40 |
'fancyvrb.sty', |
| 41 |
'fncychap.sty', |
| 42 |
'geometry.sty', |
| 43 |
'kvoptions.sty', |
| 44 |
'hyperref.sty', |
| 45 |
'booktabs.sty', |
| 46 |
] |
| 47 |
|
| 48 |
|
| 49 |
# only run latex if all needed packages are there |
| 50 |
def kpsetest(*filenames: str) -> bool: |
| 51 |
try: |
| 52 |
subprocess.run(['kpsewhich', *list(filenames)], capture_output=True, check=True) # NoQA: S607 |
| 53 |
return True |
| 54 |
except (OSError, CalledProcessError): |
| 55 |
return False # command not found or exit with non-zero |
| 56 |
|
| 57 |
|
| 58 |
# compile latex document with app.config.latex_engine |
| 59 |
def compile_latex_document( |
| 60 |
app: SphinxTestApp, |
| 61 |
filename: str = 'projectnamenotset.tex', |
| 62 |
docclass: str = 'manual', |
| 63 |
runtwice: bool = False, |
| 64 |
) -> None: |
| 65 |
# now, try to run latex over it |
| 66 |
try: |
| 67 |
with chdir(app.outdir): |
| 68 |
# name latex output-directory according to both engine and docclass |
| 69 |
# to avoid reuse of auxiliary files by one docclass from another |
| 70 |
latex_outputdir = app.config.latex_engine + docclass |
| 71 |
ensuredir(latex_outputdir) |
| 72 |
# keep a copy of latex file for this engine in case test fails |
| 73 |
copyfile(filename, latex_outputdir + '/' + filename) |
| 74 |
args = [ |
| 75 |
app.config.latex_engine, |
| 76 |
'--halt-on-error', |
| 77 |
'--interaction=nonstopmode', |
| 78 |
f'-output-directory={latex_outputdir}', |
| 79 |
filename, |
| 80 |
] |
| 81 |
subprocess.run(args, capture_output=True, check=True) |
| 82 |
# Run a second time (if engine is pdflatex), to have a chance to |
| 83 |
# detect problems caused on second LaTeX pass (for example, this |
| 84 |
# is required for the TOC in PDF to show up, for internal |
| 85 |
# hyperlinks to actually work). Of course, this increases |
| 86 |
# duration of test, but also its usefulness. |
| 87 |
# TODO: in theory the correct way is to run Latexmk with options |
| 88 |
# as configured in the Makefile and in presence of latexmkrc |
| 89 |
# or latexmkjarc and also sphinx.xdy and other xindy support. |
| 90 |
# And two passes are not enough except for simplest documents. |
| 91 |
if runtwice: |
| 92 |
subprocess.run(args, capture_output=True, check=True) |
| 93 |
except OSError as exc: # most likely the latex executable was not found |
| 94 |
raise pytest.skip.Exception from exc |
| 95 |
except CalledProcessError as exc: |
| 96 |
print(exc.stdout.decode('utf8')) |
| 97 |
print(exc.stderr.decode('utf8')) |
| 98 |
msg = f'{app.config.latex_engine} exited with return code {exc.returncode}' |
| 99 |
raise AssertionError(msg) from exc |
| 100 |
|
| 101 |
|
| 102 |
skip_if_requested = pytest.mark.skipif( |
| 103 |
'SKIP_LATEX_BUILD' in os.environ, |
| 104 |
reason='Skip LaTeX builds because SKIP_LATEX_BUILD is set', |
| 105 |
) |
| 106 |
skip_if_stylefiles_notfound = pytest.mark.skipif( |
| 107 |
not kpsetest(*STYLEFILES), |
| 108 |
reason='not running latex, the required styles do not seem to be installed', |
| 109 |
) |
| 110 |
skip_if_docutils_not_at_least_at_0_22 = pytest.mark.skipif( |
| 111 |
docutils.__version_info__[:2] < (0, 22), |
| 112 |
reason='this test requires Docutils at least at 0.22', |
| 113 |
) |
| 114 |
|
| 115 |
|
| 116 |
class RemoteImageHandler(http.server.BaseHTTPRequestHandler): |
| 117 |
protocol_version = 'HTTP/1.1' |
| 118 |
|
| 119 |
def do_GET(self) -> None: |
| 120 |
if self.path != '/sphinx.png': |
| 121 |
self._send_not_found() |
| 122 |
return |
| 123 |
|
| 124 |
img_path = TEST_ROOTS_DIR / 'test-local-logo' / 'images' / 'img.png' |
| 125 |
content = img_path.read_bytes() |
| 126 |
self._send_bytes(content, 'image/png') |
| 127 |
|
| 128 |
def _send_bytes(self, content: bytes, content_type: str) -> None: |
| 129 |
self.send_response(200, 'OK') |
| 130 |
self.send_header('Content-Length', str(len(content))) |
| 131 |
self.send_header('Content-Type', content_type) |
| 132 |
self.end_headers() |
| 133 |
self.wfile.write(content) |
| 134 |
|
| 135 |
def _send_not_found(self) -> None: |
| 136 |
self.send_response(404, 'Not Found') |
| 137 |
self.send_header('Content-Length', '0') |
| 138 |
self.end_headers() |
| 139 |
|
| 140 |
|
| 141 |
@skip_if_requested |
| 142 |
@skip_if_stylefiles_notfound |
| 143 |
@pytest.mark.parametrize( |
| 144 |
('engine', 'docclass', 'python_maximum_signature_line_length', 'runtwice'), |
| 145 |
# Only running test with `python_maximum_signature_line_length` not None with last |
| 146 |
# LaTeX engine to reduce testing time, as if this configuration does not fail with |
| 147 |
# one engine, it's almost impossible it would fail with another. |
| 148 |
[ |
| 149 |
('pdflatex', 'manual', None, True), |
| 150 |
('pdflatex', 'howto', None, True), |
| 151 |
('lualatex', 'manual', None, False), |
| 152 |
('lualatex', 'howto', None, False), |
| 153 |
('xelatex', 'manual', 1, False), |
| 154 |
('xelatex', 'howto', 1, False), |
| 155 |
], |
| 156 |
) |
| 157 |
@pytest.mark.sphinx( |
| 158 |
'latex', |
| 159 |
testroot='root', |
| 160 |
freshenv=True, |
| 161 |
) |
| 162 |
def test_build_latex_doc( |
| 163 |
app: SphinxTestApp, |
| 164 |
engine: str, |
| 165 |
docclass: str, |
| 166 |
python_maximum_signature_line_length: int | None, |
| 167 |
runtwice: bool, |
| 168 |
) -> None: |
| 169 |
app.config.python_maximum_signature_line_length = ( |
| 170 |
python_maximum_signature_line_length |
| 171 |
) |
| 172 |
app.config.intersphinx_mapping = { |
| 173 |
'sphinx': ('https://www.sphinx-doc.org/en/master/', None), |
| 174 |
} |
| 175 |
intersphinx_setup(app) |
| 176 |
app.config.latex_engine = engine |
| 177 |
app.config.latex_documents = [(*app.config.latex_documents[0][:4], docclass)] |
| 178 |
if engine == 'xelatex': |
| 179 |
app.config.latex_table_style = ['booktabs'] |
| 180 |
elif engine == 'lualatex': |
| 181 |
app.config.latex_table_style = ['colorrows'] |
| 182 |
validate_intersphinx_mapping(app, app.config) |
| 183 |
load_mappings(app) |
| 184 |
app.builder.init() |
| 185 |
LaTeXTranslator.ignore_missing_images = True |
| 186 |
with http_server(RemoteImageHandler): |
| 187 |
app.build(force_all=True) |
| 188 |
|
| 189 |
# file from latex_additional_files |
| 190 |
assert (app.outdir / 'svgimg.svg').is_file() |
| 191 |
|
| 192 |
compile_latex_document(app, 'sphinxtests.tex', docclass, runtwice) |
| 193 |
|
| 194 |
|
| 195 |
@skip_if_requested |
| 196 |
@skip_if_stylefiles_notfound |
| 197 |
@skip_if_docutils_not_at_least_at_0_22 |
| 198 |
@pytest.mark.parametrize('engine', ['pdflatex', 'lualatex', 'xelatex']) |
| 199 |
@pytest.mark.sphinx( |
| 200 |
'latex', |
| 201 |
testroot='latex-images-css3-lengths', |
| 202 |
) |
| 203 |
def test_build_latex_with_css3_lengths(app: SphinxTestApp, engine: str) -> None: |
| 204 |
app.config.latex_engine = engine |
| 205 |
app.config.latex_documents = [(*app.config.latex_documents[0][:4], 'howto')] |
| 206 |
app.builder.init() |
| 207 |
app.build(force_all=True) |
| 208 |
compile_latex_document(app, docclass='howto') |
| 209 |
|
| 210 |
|
| 211 |
@pytest.mark.sphinx('latex', testroot='root') |
| 212 |
def test_writer(app: SphinxTestApp) -> None: |
| 213 |
app.build(force_all=True) |
| 214 |
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8') |
| 215 |
|
| 216 |
assert ( |
| 217 |
'\\begin{sphinxfigure-in-table}\n\\centering\n\\capstart\n' |
| 218 |
'\\noindent\\sphinxincludegraphics{{img}.png}\n' |
| 219 |
'\\sphinxfigcaption{figure in table}\\label{\\detokenize{markup:id8}}' |
| 220 |
'\\end{sphinxfigure-in-table}\\relax' |
| 221 |
) in result |
| 222 |
|
| 223 |
assert ( |
| 224 |
'\\begin{wrapfigure}{r}{0pt}\n\\centering\n' |
| 225 |
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n' |
| 226 |
'\\caption{figure with align option}\\label{\\detokenize{markup:id10}}' |
| 227 |
'\\end{wrapfigure}\n\n' |
| 228 |
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' |
| 229 |
) in result |
| 230 |
|
| 231 |
assert ( |
| 232 |
'\\begin{wrapfigure}{r}{0.500\\linewidth}\n\\centering\n' |
| 233 |
'\\noindent\\sphinxincludegraphics{{rimg}.png}\n' |
| 234 |
'\\caption{figure with align \\& figwidth option}' |
| 235 |
'\\label{\\detokenize{markup:id11}}' |
| 236 |
'\\end{wrapfigure}\n\n' |
| 237 |
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' |
| 238 |
) in result |
| 239 |
|
| 240 |
assert ( |
| 241 |
'\\begin{wrapfigure}{r}{3cm}\n\\centering\n' |
| 242 |
'\\noindent\\sphinxincludegraphics[width=3cm]{{rimg}.png}\n' |
| 243 |
'\\caption{figure with align \\& width option}' |
| 244 |
'\\label{\\detokenize{markup:id12}}' |
| 245 |
'\\end{wrapfigure}\n\n' |
| 246 |
'\\mbox{}\\par\\vskip-\\dimexpr\\baselineskip+\\parskip\\relax' |
| 247 |
) in result |
| 248 |
|
| 249 |
assert 'Footnotes' not in result |
| 250 |
|
| 251 |
assert ( |
| 252 |
'\\begin{sphinxseealso}{See also:}\n\n' |
| 253 |
'\\sphinxAtStartPar\n' |
| 254 |
'something, something else, something more\n' |
| 255 |
'\\begin{description}\n' |
| 256 |
'\\sphinxlineitem{\\sphinxhref{https://www.google.com}{Google}}\n' |
| 257 |
'\\sphinxAtStartPar\n' |
| 258 |
'For everything.\n' |
| 259 |
'\n' |
| 260 |
'\\end{description}\n' |
| 261 |
'\n\n\\end{sphinxseealso}\n\n' |
| 262 |
) in result |
| 263 |
|
| 264 |
|
| 265 |
@pytest.mark.sphinx('latex', testroot='basic') |
| 266 |
def test_latex_basic(app: SphinxTestApp) -> None: |
| 267 |
app.build(force_all=True) |
| 268 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 269 |
print(result) |
| 270 |
print(app.status.getvalue()) |
| 271 |
print(app.warning.getvalue()) |
| 272 |
assert r'\title{The basic Sphinx documentation for testing}' in result |
| 273 |
assert r'\release{}' in result |
| 274 |
assert r'\renewcommand{\releasename}{}' in result |
| 275 |
|
| 276 |
|
| 277 |
@pytest.mark.sphinx( |
| 278 |
'latex', |
| 279 |
testroot='basic', |
| 280 |
confoverrides={ |
| 281 |
'latex_documents': [('index', 'test.tex', 'title', 'author', 'manual')], |
| 282 |
}, |
| 283 |
) |
| 284 |
def test_latex_basic_manual(app: SphinxTestApp) -> None: |
| 285 |
app.build(force_all=True) |
| 286 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 287 |
print(result) |
| 288 |
assert r'\def\sphinxdocclass{report}' in result |
| 289 |
assert r'\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result |
| 290 |
|
| 291 |
|
| 292 |
@pytest.mark.sphinx( |
| 293 |
'latex', |
| 294 |
testroot='basic', |
| 295 |
confoverrides={ |
| 296 |
'latex_documents': [('index', 'test.tex', 'title', 'author', 'howto')], |
| 297 |
}, |
| 298 |
) |
| 299 |
def test_latex_basic_howto(app: SphinxTestApp) -> None: |
| 300 |
app.build(force_all=True) |
| 301 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 302 |
print(result) |
| 303 |
assert r'\def\sphinxdocclass{article}' in result |
| 304 |
assert r'\documentclass[letterpaper,10pt,english]{sphinxhowto}' in result |
| 305 |
|
| 306 |
|
| 307 |
@pytest.mark.sphinx( |
| 308 |
'latex', |
| 309 |
testroot='basic', |
| 310 |
confoverrides={ |
| 311 |
'language': 'ja', |
| 312 |
'latex_documents': [('index', 'test.tex', 'title', 'author', 'manual')], |
| 313 |
}, |
| 314 |
) |
| 315 |
def test_latex_basic_manual_ja(app: SphinxTestApp) -> None: |
| 316 |
app.build(force_all=True) |
| 317 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 318 |
print(result) |
| 319 |
assert r'\def\sphinxdocclass{ujbook}' in result |
| 320 |
assert r'\documentclass[letterpaper,10pt,dvipdfmx]{sphinxmanual}' in result |
| 321 |
|
| 322 |
|
| 323 |
@pytest.mark.sphinx( |
| 324 |
'latex', |
| 325 |
testroot='basic', |
| 326 |
confoverrides={ |
| 327 |
'language': 'ja', |
| 328 |
'latex_documents': [('index', 'test.tex', 'title', 'author', 'howto')], |
| 329 |
}, |
| 330 |
) |
| 331 |
def test_latex_basic_howto_ja(app: SphinxTestApp) -> None: |
| 332 |
app.build(force_all=True) |
| 333 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 334 |
print(result) |
| 335 |
assert r'\def\sphinxdocclass{ujreport}' in result |
| 336 |
assert r'\documentclass[letterpaper,10pt,dvipdfmx]{sphinxhowto}' in result |
| 337 |
|
| 338 |
|
| 339 |
@pytest.mark.sphinx('latex', testroot='latex-theme') |
| 340 |
def test_latex_theme(app: SphinxTestApp) -> None: |
| 341 |
app.build(force_all=True) |
| 342 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 343 |
print(result) |
| 344 |
assert r'\def\sphinxdocclass{book}' in result |
| 345 |
assert r'\documentclass[a4paper,12pt,english]{sphinxbook}' in result |
| 346 |
|
| 347 |
|
| 348 |
@pytest.mark.sphinx( |
| 349 |
'latex', |
| 350 |
testroot='latex-theme', |
| 351 |
confoverrides={'latex_elements': {'papersize': 'b5paper', 'pointsize': '9pt'}}, |
| 352 |
) |
| 353 |
def test_latex_theme_papersize(app: SphinxTestApp) -> None: |
| 354 |
app.build(force_all=True) |
| 355 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 356 |
print(result) |
| 357 |
assert r'\def\sphinxdocclass{book}' in result |
| 358 |
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result |
| 359 |
|
| 360 |
|
| 361 |
@pytest.mark.sphinx( |
| 362 |
'latex', |
| 363 |
testroot='latex-theme', |
| 364 |
confoverrides={'latex_theme_options': {'papersize': 'b5paper', 'pointsize': '9pt'}}, |
| 365 |
) |
| 366 |
def test_latex_theme_options(app: SphinxTestApp) -> None: |
| 367 |
app.build(force_all=True) |
| 368 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 369 |
print(result) |
| 370 |
assert r'\def\sphinxdocclass{book}' in result |
| 371 |
assert r'\documentclass[b5paper,9pt,english]{sphinxbook}' in result |
| 372 |
|
| 373 |
|
| 374 |
@pytest.mark.sphinx( |
| 375 |
'latex', |
| 376 |
testroot='basic', |
| 377 |
confoverrides={'language': 'zh'}, |
| 378 |
) |
| 379 |
def test_latex_additional_settings_for_language_code(app: SphinxTestApp) -> None: |
| 380 |
app.build(force_all=True) |
| 381 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 382 |
print(result) |
| 383 |
print(app.status.getvalue()) |
| 384 |
print(app.warning.getvalue()) |
| 385 |
assert r'\usepackage{xeCJK}' in result |
| 386 |
|
| 387 |
|
| 388 |
@pytest.mark.sphinx( |
| 389 |
'latex', |
| 390 |
testroot='basic', |
| 391 |
confoverrides={'language': 'el'}, |
| 392 |
) |
| 393 |
def test_latex_additional_settings_for_greek(app: SphinxTestApp) -> None: |
| 394 |
app.build(force_all=True) |
| 395 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 396 |
print(result) |
| 397 |
print(app.status.getvalue()) |
| 398 |
print(app.warning.getvalue()) |
| 399 |
assert '\\usepackage{polyglossia}\n\\setmainlanguage{greek}' in result |
| 400 |
assert '\\newfontfamily\\greekfonttt{FreeMono}' in result |
| 401 |
|
| 402 |
|
| 403 |
@pytest.mark.sphinx('latex', testroot='latex-title') |
| 404 |
def test_latex_title_after_admonitions(app: SphinxTestApp) -> None: |
| 405 |
app.build(force_all=True) |
| 406 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 407 |
print(result) |
| 408 |
print(app.status.getvalue()) |
| 409 |
print(app.warning.getvalue()) |
| 410 |
assert '\\title{test\\sphinxhyphen{}latex\\sphinxhyphen{}title}' in result |
| 411 |
|
| 412 |
|
| 413 |
@pytest.mark.sphinx( |
| 414 |
'latex', |
| 415 |
testroot='basic', |
| 416 |
confoverrides={'release': '1.0_0'}, |
| 417 |
) |
| 418 |
def test_latex_release(app: SphinxTestApp) -> None: |
| 419 |
app.build(force_all=True) |
| 420 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 421 |
print(result) |
| 422 |
print(app.status.getvalue()) |
| 423 |
print(app.warning.getvalue()) |
| 424 |
assert r'\release{1.0\_0}' in result |
| 425 |
assert r'\renewcommand{\releasename}{Release}' in result |
| 426 |
|
| 427 |
|
| 428 |
@pytest.mark.sphinx( |
| 429 |
'latex', |
| 430 |
testroot='numfig', |
| 431 |
confoverrides={'numfig': True}, |
| 432 |
) |
| 433 |
def test_numref(app: SphinxTestApp) -> None: |
| 434 |
app.build(force_all=True) |
| 435 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 436 |
print(result) |
| 437 |
print(app.status.getvalue()) |
| 438 |
print(app.warning.getvalue()) |
| 439 |
assert ( |
| 440 |
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\@ \\ref{\\detokenize{index:fig1}}}' |
| 441 |
) in result |
| 442 |
assert ( |
| 443 |
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' |
| 444 |
) in result |
| 445 |
assert ( |
| 446 |
'\\hyperref[\\detokenize{index:table-1}]' |
| 447 |
'{Table \\ref{\\detokenize{index:table-1}}}' |
| 448 |
) in result |
| 449 |
assert ( |
| 450 |
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' |
| 451 |
) in result |
| 452 |
assert ( |
| 453 |
'\\hyperref[\\detokenize{index:code-1}]' |
| 454 |
'{Listing \\ref{\\detokenize{index:code-1}}}' |
| 455 |
) in result |
| 456 |
assert ( |
| 457 |
'\\hyperref[\\detokenize{baz:code22}]' |
| 458 |
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}' |
| 459 |
) in result |
| 460 |
assert ( |
| 461 |
'\\hyperref[\\detokenize{foo:foo}]{Section \\ref{\\detokenize{foo:foo}}}' |
| 462 |
) in result |
| 463 |
assert ( |
| 464 |
'\\hyperref[\\detokenize{bar:bar-a}]{Section \\ref{\\detokenize{bar:bar-a}}}' |
| 465 |
) in result |
| 466 |
assert ( |
| 467 |
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} ' |
| 468 |
'\\nameref{\\detokenize{index:fig1}}}' |
| 469 |
) in result |
| 470 |
assert ( |
| 471 |
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' |
| 472 |
'\\nameref{\\detokenize{foo:foo}}}' |
| 473 |
) in result |
| 474 |
|
| 475 |
# sphinxmessages.sty |
| 476 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 477 |
print(result) |
| 478 |
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 479 |
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table }}' in result |
| 480 |
assert ( |
| 481 |
r'\addto\captionsenglish{\renewcommand{\literalblockname}{Listing}}' |
| 482 |
) in result |
| 483 |
|
| 484 |
|
| 485 |
@pytest.mark.sphinx( |
| 486 |
'latex', |
| 487 |
testroot='numfig', |
| 488 |
confoverrides={ |
| 489 |
'numfig': True, |
| 490 |
'numfig_format': { |
| 491 |
'figure': 'Figure:%s', |
| 492 |
'table': 'Tab_%s', |
| 493 |
'code-block': 'Code-%s', |
| 494 |
'section': 'SECTION-%s', |
| 495 |
}, |
| 496 |
}, |
| 497 |
) |
| 498 |
def test_numref_with_prefix1(app: SphinxTestApp) -> None: |
| 499 |
app.build(force_all=True) |
| 500 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 501 |
print(result) |
| 502 |
print(app.status.getvalue()) |
| 503 |
print(app.warning.getvalue()) |
| 504 |
assert '\\ref{\\detokenize{index:fig1}}' in result |
| 505 |
assert '\\ref{\\detokenize{baz:fig22}}' in result |
| 506 |
assert '\\ref{\\detokenize{index:table-1}}' in result |
| 507 |
assert '\\ref{\\detokenize{baz:table22}}' in result |
| 508 |
assert '\\ref{\\detokenize{index:code-1}}' in result |
| 509 |
assert '\\ref{\\detokenize{baz:code22}}' in result |
| 510 |
assert ( |
| 511 |
'\\hyperref[\\detokenize{index:fig1}]{Figure:\\ref{\\detokenize{index:fig1}}}' |
| 512 |
) in result |
| 513 |
assert ( |
| 514 |
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' |
| 515 |
) in result |
| 516 |
assert ( |
| 517 |
'\\hyperref[\\detokenize{index:table-1}]' |
| 518 |
'{Tab\\_\\ref{\\detokenize{index:table-1}}}' |
| 519 |
) in result |
| 520 |
assert ( |
| 521 |
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' |
| 522 |
) in result |
| 523 |
assert ( |
| 524 |
'\\hyperref[\\detokenize{index:code-1}]' |
| 525 |
'{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}}}' |
| 526 |
) in result |
| 527 |
assert ( |
| 528 |
'\\hyperref[\\detokenize{baz:code22}]' |
| 529 |
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}' |
| 530 |
) in result |
| 531 |
assert ( |
| 532 |
'\\hyperref[\\detokenize{foo:foo}]' |
| 533 |
'{SECTION\\sphinxhyphen{}\\ref{\\detokenize{foo:foo}}}' |
| 534 |
) in result |
| 535 |
assert ( |
| 536 |
'\\hyperref[\\detokenize{bar:bar-a}]' |
| 537 |
'{SECTION\\sphinxhyphen{}\\ref{\\detokenize{bar:bar-a}}}' |
| 538 |
) in result |
| 539 |
assert ( |
| 540 |
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} ' |
| 541 |
'\\nameref{\\detokenize{index:fig1}}}' |
| 542 |
) in result |
| 543 |
assert ( |
| 544 |
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' |
| 545 |
'\\nameref{\\detokenize{foo:foo}}}' |
| 546 |
) in result |
| 547 |
|
| 548 |
# sphinxmessages.sty |
| 549 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 550 |
print(result) |
| 551 |
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result |
| 552 |
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result |
| 553 |
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result |
| 554 |
|
| 555 |
|
| 556 |
@pytest.mark.sphinx( |
| 557 |
'latex', |
| 558 |
testroot='numfig', |
| 559 |
confoverrides={ |
| 560 |
'numfig': True, |
| 561 |
'numfig_format': { |
| 562 |
'figure': 'Figure:%s.', |
| 563 |
'table': 'Tab_%s:', |
| 564 |
'code-block': 'Code-%s | ', |
| 565 |
'section': 'SECTION_%s_', |
| 566 |
}, |
| 567 |
}, |
| 568 |
) |
| 569 |
def test_numref_with_prefix2(app: SphinxTestApp) -> None: |
| 570 |
app.build(force_all=True) |
| 571 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 572 |
print(result) |
| 573 |
print(app.status.getvalue()) |
| 574 |
print(app.warning.getvalue()) |
| 575 |
assert ( |
| 576 |
'\\hyperref[\\detokenize{index:fig1}]' |
| 577 |
'{Figure:\\ref{\\detokenize{index:fig1}}.\\@}' |
| 578 |
) in result |
| 579 |
assert ( |
| 580 |
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' |
| 581 |
) in result |
| 582 |
assert ( |
| 583 |
'\\hyperref[\\detokenize{index:table-1}]' |
| 584 |
'{Tab\\_\\ref{\\detokenize{index:table-1}}:}' |
| 585 |
) in result |
| 586 |
assert ( |
| 587 |
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' |
| 588 |
) in result |
| 589 |
assert ( |
| 590 |
'\\hyperref[\\detokenize{index:code-1}]{Code\\sphinxhyphen{}\\ref{\\detokenize{index:code-1}} ' |
| 591 |
'| }' |
| 592 |
) in result |
| 593 |
assert ( |
| 594 |
'\\hyperref[\\detokenize{baz:code22}]' |
| 595 |
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}' |
| 596 |
) in result |
| 597 |
assert ( |
| 598 |
'\\hyperref[\\detokenize{foo:foo}]{SECTION\\_\\ref{\\detokenize{foo:foo}}\\_}' |
| 599 |
) in result |
| 600 |
assert ( |
| 601 |
'\\hyperref[\\detokenize{bar:bar-a}]' |
| 602 |
'{SECTION\\_\\ref{\\detokenize{bar:bar-a}}\\_}' |
| 603 |
) in result |
| 604 |
assert ( |
| 605 |
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} ' |
| 606 |
'\\nameref{\\detokenize{index:fig1}}}' |
| 607 |
) in result |
| 608 |
assert ( |
| 609 |
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' |
| 610 |
'\\nameref{\\detokenize{foo:foo}}}' |
| 611 |
) in result |
| 612 |
|
| 613 |
# sphinxmessages.sty |
| 614 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 615 |
print(result) |
| 616 |
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Figure:}}' in result |
| 617 |
assert r'\def\fnum@figure{\figurename\thefigure{}.}' in result |
| 618 |
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Tab\_}}' in result |
| 619 |
assert r'\def\fnum@table{\tablename\thetable{}:}' in result |
| 620 |
assert r'\addto\captionsenglish{\renewcommand{\literalblockname}{Code-}}' in result |
| 621 |
|
| 622 |
|
| 623 |
@pytest.mark.sphinx( |
| 624 |
'latex', |
| 625 |
testroot='numfig', |
| 626 |
confoverrides={'numfig': True, 'language': 'ja'}, |
| 627 |
) |
| 628 |
def test_numref_with_language_ja(app: SphinxTestApp) -> None: |
| 629 |
app.build() |
| 630 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 631 |
print(result) |
| 632 |
print(app.status.getvalue()) |
| 633 |
print(app.warning.getvalue()) |
| 634 |
assert ( |
| 635 |
'\\hyperref[\\detokenize{index:fig1}]{\u56f3 \\ref{\\detokenize{index:fig1}}}' |
| 636 |
) in result |
| 637 |
assert ( |
| 638 |
'\\hyperref[\\detokenize{baz:fig22}]{Figure\\ref{\\detokenize{baz:fig22}}}' |
| 639 |
) in result |
| 640 |
assert ( |
| 641 |
'\\hyperref[\\detokenize{index:table-1}]' |
| 642 |
'{\u8868 \\ref{\\detokenize{index:table-1}}}' |
| 643 |
) in result |
| 644 |
assert ( |
| 645 |
'\\hyperref[\\detokenize{baz:table22}]{Table:\\ref{\\detokenize{baz:table22}}}' |
| 646 |
) in result |
| 647 |
assert ( |
| 648 |
'\\hyperref[\\detokenize{index:code-1}]' |
| 649 |
'{\u30ea\u30b9\u30c8 \\ref{\\detokenize{index:code-1}}}' |
| 650 |
) in result |
| 651 |
assert ( |
| 652 |
'\\hyperref[\\detokenize{baz:code22}]' |
| 653 |
'{Code\\sphinxhyphen{}\\ref{\\detokenize{baz:code22}}}' |
| 654 |
) in result |
| 655 |
assert ( |
| 656 |
'\\hyperref[\\detokenize{foo:foo}]{\\ref{\\detokenize{foo:foo}} \u7ae0}' |
| 657 |
) in result |
| 658 |
assert ( |
| 659 |
'\\hyperref[\\detokenize{bar:bar-a}]{\\ref{\\detokenize{bar:bar-a}} \u7ae0}' |
| 660 |
) in result |
| 661 |
assert ( |
| 662 |
'\\hyperref[\\detokenize{index:fig1}]{Fig.\\ref{\\detokenize{index:fig1}} ' |
| 663 |
'\\nameref{\\detokenize{index:fig1}}}' |
| 664 |
) in result |
| 665 |
assert ( |
| 666 |
'\\hyperref[\\detokenize{foo:foo}]{Sect.\\ref{\\detokenize{foo:foo}} ' |
| 667 |
'\\nameref{\\detokenize{foo:foo}}}' |
| 668 |
) in result |
| 669 |
|
| 670 |
# sphinxmessages.sty |
| 671 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 672 |
print(result) |
| 673 |
assert '\\@iden{\\renewcommand{\\figurename}{図 }}' in result |
| 674 |
assert '\\@iden{\\renewcommand{\\tablename}{表 }}' in result |
| 675 |
assert '\\@iden{\\renewcommand{\\literalblockname}{リスト}}' in result |
| 676 |
|
| 677 |
|
| 678 |
@pytest.mark.sphinx('latex', testroot='latex-numfig') |
| 679 |
def test_latex_obey_numfig_is_false(app: SphinxTestApp) -> None: |
| 680 |
app.build(force_all=True) |
| 681 |
|
| 682 |
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8') |
| 683 |
assert '\\usepackage{sphinx}' in result |
| 684 |
|
| 685 |
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8') |
| 686 |
assert '\\usepackage{sphinx}' in result |
| 687 |
|
| 688 |
|
| 689 |
@pytest.mark.sphinx( |
| 690 |
'latex', |
| 691 |
testroot='latex-numfig', |
| 692 |
confoverrides={'numfig': True, 'numfig_secnum_depth': 0}, |
| 693 |
) |
| 694 |
def test_latex_obey_numfig_secnum_depth_is_zero(app: SphinxTestApp) -> None: |
| 695 |
app.build(force_all=True) |
| 696 |
|
| 697 |
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8') |
| 698 |
assert '\\usepackage[,nonumfigreset,mathnumfig,mathnumsep={.}]{sphinx}' in result |
| 699 |
|
| 700 |
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8') |
| 701 |
assert '\\usepackage[,nonumfigreset,mathnumfig,mathnumsep={.}]{sphinx}' in result |
| 702 |
|
| 703 |
|
| 704 |
@pytest.mark.sphinx( |
| 705 |
'latex', |
| 706 |
testroot='latex-numfig', |
| 707 |
confoverrides={'numfig': True, 'numfig_secnum_depth': 2, 'math_numsep': '-'}, |
| 708 |
) |
| 709 |
def test_latex_obey_numfig_secnum_depth_is_two(app: SphinxTestApp) -> None: |
| 710 |
app.build(force_all=True) |
| 711 |
|
| 712 |
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8') |
| 713 |
assert '\\usepackage[,numfigreset=2,mathnumfig,mathnumsep={-}]{sphinx}' in result |
| 714 |
|
| 715 |
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8') |
| 716 |
assert '\\usepackage[,numfigreset=3,mathnumfig,mathnumsep={-}]{sphinx}' in result |
| 717 |
|
| 718 |
|
| 719 |
@pytest.mark.sphinx( |
| 720 |
'latex', |
| 721 |
testroot='latex-numfig', |
| 722 |
confoverrides={'numfig': True, 'math_numfig': False}, |
| 723 |
) |
| 724 |
def test_latex_obey_numfig_but_math_numfig_false(app: SphinxTestApp) -> None: |
| 725 |
app.build(force_all=True) |
| 726 |
|
| 727 |
result = (app.outdir / 'SphinxManual.tex').read_text(encoding='utf8') |
| 728 |
assert '\\usepackage[,numfigreset=1]{sphinx}' in result |
| 729 |
|
| 730 |
result = (app.outdir / 'SphinxHowTo.tex').read_text(encoding='utf8') |
| 731 |
assert '\\usepackage[,numfigreset=2]{sphinx}' in result |
| 732 |
|
| 733 |
|
| 734 |
@pytest.mark.sphinx('latex', testroot='basic') |
| 735 |
def test_latex_add_latex_package(app: SphinxTestApp) -> None: |
| 736 |
app.add_latex_package('foo') |
| 737 |
app.add_latex_package('bar', 'baz') |
| 738 |
app.build(force_all=True) |
| 739 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 740 |
assert '\\usepackage{foo}' in result |
| 741 |
assert '\\usepackage[baz]{bar}' in result |
| 742 |
|
| 743 |
|
| 744 |
@pytest.mark.sphinx('latex', testroot='latex-babel') |
| 745 |
def test_babel_with_no_language_settings(app: SphinxTestApp) -> None: |
| 746 |
app.build(force_all=True) |
| 747 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 748 |
print(result) |
| 749 |
print(app.status.getvalue()) |
| 750 |
print(app.warning.getvalue()) |
| 751 |
assert '\\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result |
| 752 |
assert '\\usepackage{babel}' in result |
| 753 |
assert '\\usepackage{tgtermes}' in result |
| 754 |
assert '\\usepackage[Bjarne]{fncychap}' in result |
| 755 |
assert ( |
| 756 |
'\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 757 |
) in result |
| 758 |
assert '\\shorthandoff{"}' in result |
| 759 |
|
| 760 |
# sphinxmessages.sty |
| 761 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 762 |
print(result) |
| 763 |
assert r'\def\pageautorefname{page}' in result |
| 764 |
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 765 |
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 766 |
|
| 767 |
|
| 768 |
@pytest.mark.sphinx( |
| 769 |
'latex', |
| 770 |
testroot='latex-babel', |
| 771 |
confoverrides={'language': 'de'}, |
| 772 |
) |
| 773 |
def test_babel_with_language_de(app: SphinxTestApp) -> None: |
| 774 |
app.build(force_all=True) |
| 775 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 776 |
print(result) |
| 777 |
print(app.status.getvalue()) |
| 778 |
print(app.warning.getvalue()) |
| 779 |
assert '\\documentclass[letterpaper,10pt,ngerman]{sphinxmanual}' in result |
| 780 |
assert '\\usepackage{babel}' in result |
| 781 |
assert '\\usepackage{tgtermes}' in result |
| 782 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 783 |
assert ( |
| 784 |
'\\addto\\captionsngerman{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 785 |
) in result |
| 786 |
assert '\\shorthandoff{"}' in result |
| 787 |
|
| 788 |
# sphinxmessages.sty |
| 789 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 790 |
print(result) |
| 791 |
assert r'\def\pageautorefname{Seite}' in result |
| 792 |
assert r'\addto\captionsngerman{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 793 |
assert r'\addto\captionsngerman{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 794 |
|
| 795 |
|
| 796 |
@pytest.mark.sphinx( |
| 797 |
'latex', |
| 798 |
testroot='latex-babel', |
| 799 |
confoverrides={'language': 'ru'}, |
| 800 |
) |
| 801 |
def test_babel_with_language_ru(app: SphinxTestApp) -> None: |
| 802 |
app.build(force_all=True) |
| 803 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 804 |
print(result) |
| 805 |
print(app.status.getvalue()) |
| 806 |
print(app.warning.getvalue()) |
| 807 |
assert '\\documentclass[letterpaper,10pt,russian]{sphinxmanual}' in result |
| 808 |
assert '\\usepackage{babel}' in result |
| 809 |
assert '\\usepackage{tgtermes}' not in result |
| 810 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 811 |
assert ( |
| 812 |
'\\addto\\captionsrussian{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 813 |
) in result |
| 814 |
assert '\\shorthandoff{"}' in result |
| 815 |
|
| 816 |
# sphinxmessages.sty |
| 817 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 818 |
print(result) |
| 819 |
assert r'\def\pageautorefname{страница}' in result |
| 820 |
assert r'\addto\captionsrussian{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 821 |
assert r'\addto\captionsrussian{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 822 |
|
| 823 |
|
| 824 |
@pytest.mark.sphinx( |
| 825 |
'latex', |
| 826 |
testroot='latex-babel', |
| 827 |
confoverrides={'language': 'tr'}, |
| 828 |
) |
| 829 |
def test_babel_with_language_tr(app: SphinxTestApp) -> None: |
| 830 |
app.build(force_all=True) |
| 831 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 832 |
print(result) |
| 833 |
print(app.status.getvalue()) |
| 834 |
print(app.warning.getvalue()) |
| 835 |
assert '\\documentclass[letterpaper,10pt,turkish]{sphinxmanual}' in result |
| 836 |
assert '\\usepackage{babel}' in result |
| 837 |
assert '\\usepackage{tgtermes}' in result |
| 838 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 839 |
assert ( |
| 840 |
'\\addto\\captionsturkish{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 841 |
) in result |
| 842 |
assert '\\shorthandoff{=}' in result |
| 843 |
|
| 844 |
# sphinxmessages.sty |
| 845 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 846 |
print(result) |
| 847 |
assert r'\def\pageautorefname{sayfa}' in result |
| 848 |
assert r'\addto\captionsturkish{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 849 |
assert r'\addto\captionsturkish{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 850 |
|
| 851 |
|
| 852 |
@pytest.mark.sphinx( |
| 853 |
'latex', |
| 854 |
testroot='latex-babel', |
| 855 |
confoverrides={'language': 'ja'}, |
| 856 |
) |
| 857 |
def test_babel_with_language_ja(app: SphinxTestApp) -> None: |
| 858 |
app.build(force_all=True) |
| 859 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 860 |
print(result) |
| 861 |
print(app.status.getvalue()) |
| 862 |
print(app.warning.getvalue()) |
| 863 |
assert '\\documentclass[letterpaper,10pt,dvipdfmx]{sphinxmanual}' in result |
| 864 |
assert '\\usepackage{babel}' not in result |
| 865 |
assert '\\usepackage{tgtermes}' in result |
| 866 |
assert '\\usepackage[Sonny]{fncychap}' not in result |
| 867 |
assert '\\renewcommand{\\contentsname}{Table of content}\n' in result |
| 868 |
assert '\\shorthandoff' not in result |
| 869 |
|
| 870 |
# sphinxmessages.sty |
| 871 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 872 |
print(result) |
| 873 |
assert r'\def\pageautorefname{ページ}' in result |
| 874 |
assert '\\@iden{\\renewcommand{\\figurename}{Fig.\\@{} }}' in result |
| 875 |
assert '\\@iden{\\renewcommand{\\tablename}{Table.\\@{} }}' in result |
| 876 |
|
| 877 |
|
| 878 |
@pytest.mark.sphinx( |
| 879 |
'latex', |
| 880 |
testroot='latex-babel', |
| 881 |
confoverrides={'language': 'unknown'}, |
| 882 |
) |
| 883 |
def test_babel_with_unknown_language(app: SphinxTestApp) -> None: |
| 884 |
app.build(force_all=True) |
| 885 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 886 |
print(result) |
| 887 |
print(app.status.getvalue()) |
| 888 |
print(app.warning.getvalue()) |
| 889 |
assert '\\documentclass[letterpaper,10pt,english]{sphinxmanual}' in result |
| 890 |
assert '\\usepackage{babel}' in result |
| 891 |
assert '\\usepackage{tgtermes}' in result |
| 892 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 893 |
assert ( |
| 894 |
'\\addto\\captionsenglish{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 895 |
) in result |
| 896 |
assert '\\shorthandoff' in result |
| 897 |
|
| 898 |
assert ( |
| 899 |
"WARNING: no Babel option known for language 'unknown'" |
| 900 |
) in app.warning.getvalue() |
| 901 |
|
| 902 |
# sphinxmessages.sty |
| 903 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 904 |
print(result) |
| 905 |
assert r'\def\pageautorefname{page}' in result |
| 906 |
assert r'\addto\captionsenglish{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 907 |
assert r'\addto\captionsenglish{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 908 |
|
| 909 |
|
| 910 |
@pytest.mark.sphinx( |
| 911 |
'latex', |
| 912 |
testroot='latex-babel', |
| 913 |
confoverrides={'language': 'de', 'latex_engine': 'lualatex'}, |
| 914 |
) |
| 915 |
def test_polyglossia_with_language_de(app: SphinxTestApp) -> None: |
| 916 |
app.build(force_all=True) |
| 917 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 918 |
print(result) |
| 919 |
print(app.status.getvalue()) |
| 920 |
print(app.warning.getvalue()) |
| 921 |
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result |
| 922 |
assert '\\usepackage{polyglossia}' in result |
| 923 |
assert '\\setmainlanguage[spelling=new]{german}' in result |
| 924 |
assert '\\usepackage{tgtermes}' not in result |
| 925 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 926 |
assert ( |
| 927 |
'\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 928 |
) in result |
| 929 |
assert '\\shorthandoff' not in result |
| 930 |
|
| 931 |
# sphinxmessages.sty |
| 932 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 933 |
print(result) |
| 934 |
assert r'\def\pageautorefname{Seite}' in result |
| 935 |
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 936 |
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 937 |
|
| 938 |
|
| 939 |
@pytest.mark.sphinx( |
| 940 |
'latex', |
| 941 |
testroot='latex-babel', |
| 942 |
confoverrides={'language': 'de-1901', 'latex_engine': 'lualatex'}, |
| 943 |
) |
| 944 |
def test_polyglossia_with_language_de_1901(app: SphinxTestApp) -> None: |
| 945 |
app.build(force_all=True) |
| 946 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 947 |
print(result) |
| 948 |
print(app.status.getvalue()) |
| 949 |
print(app.warning.getvalue()) |
| 950 |
assert '\\documentclass[letterpaper,10pt,german]{sphinxmanual}' in result |
| 951 |
assert '\\usepackage{polyglossia}' in result |
| 952 |
assert '\\setmainlanguage[spelling=old]{german}' in result |
| 953 |
assert '\\usepackage{tgtermes}' not in result |
| 954 |
assert '\\usepackage[Sonny]{fncychap}' in result |
| 955 |
assert ( |
| 956 |
'\\addto\\captionsgerman{\\renewcommand{\\contentsname}{Table of content}}\n' |
| 957 |
) in result |
| 958 |
assert '\\shorthandoff' not in result |
| 959 |
|
| 960 |
# sphinxmessages.sty |
| 961 |
result = (app.outdir / 'sphinxmessages.sty').read_text(encoding='utf8') |
| 962 |
print(result) |
| 963 |
assert r'\def\pageautorefname{page}' in result |
| 964 |
assert r'\addto\captionsgerman{\renewcommand{\figurename}{Fig.\@{} }}' in result |
| 965 |
assert r'\addto\captionsgerman{\renewcommand{\tablename}{Table.\@{} }}' in result |
| 966 |
|
| 967 |
|
| 968 |
@pytest.mark.sphinx('latex', testroot='root') |
| 969 |
def test_footnote(app: SphinxTestApp) -> None: |
| 970 |
app.build(force_all=True) |
| 971 |
result = (app.outdir / 'sphinxtests.tex').read_text(encoding='utf8') |
| 972 |
print(result) |
| 973 |
print(app.status.getvalue()) |
| 974 |
print(app.warning.getvalue()) |
| 975 |
assert ( |
| 976 |
'\\sphinxAtStartPar\n%\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 977 |
'numbered\n%\n\\end{footnote}' |
| 978 |
) in result |
| 979 |
assert ( |
| 980 |
'\\begin{footnote}[2]\\sphinxAtStartFootnote\nauto numbered\n%\n\\end{footnote}' |
| 981 |
) in result |
| 982 |
assert ( |
| 983 |
'\\begin{footnote}[3]\\sphinxAtStartFootnote\nnamed\n%\n\\end{footnote}' |
| 984 |
) in result |
| 985 |
assert '\\sphinxcite{footnote:bar}' in result |
| 986 |
assert '\\bibitem[bar]{footnote:bar}\n\\sphinxAtStartPar\ncite\n' in result |
| 987 |
assert '\\sphinxcaption{Table caption \\sphinxfootnotemark[4]' in result |
| 988 |
assert ( |
| 989 |
'\\sphinxmidrule\n\\sphinxtableatstartofbodyhook%\n' |
| 990 |
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n' |
| 991 |
'footnote in table caption\n%\n\\end{footnotetext}\\ignorespaces %\n' |
| 992 |
'\\begin{footnotetext}[5]\\sphinxAtStartFootnote\n' |
| 993 |
'footnote in table header\n%\n\\end{footnotetext}\\ignorespaces ' |
| 994 |
'\\begin{varwidth}[t]{\\sphinxcolwidth{1}{2}}' |
| 995 |
'\n\\sphinxAtStartPar\n' |
| 996 |
'VIDIOC\\_CROPCAP\n' |
| 997 |
'\\sphinxbeforeendvarwidth\n' |
| 998 |
'\\end{varwidth}%\n' |
| 999 |
) in result |
| 1000 |
assert ( |
| 1001 |
'&\\begin{varwidth}[t]{\\sphinxcolwidth{1}{2}}\n' |
| 1002 |
'\\sphinxAtStartPar\n' |
| 1003 |
'Information about VIDIOC\\_CROPCAP %\n' |
| 1004 |
'\\begin{footnote}[6]\\sphinxAtStartFootnote\n' |
| 1005 |
'footnote in table not in header\n%\n\\end{footnote}\n' |
| 1006 |
'\\sphinxbeforeendvarwidth\n' |
| 1007 |
'\\end{varwidth}%\n\\\\\n' |
| 1008 |
'\\sphinxbottomrule\n\\end{tabulary}\n' |
| 1009 |
'\\sphinxtableafterendhook\\par\n\\sphinxattableend\\end{savenotes}\n' |
| 1010 |
) in result |
| 1011 |
|
| 1012 |
|
| 1013 |
@pytest.mark.sphinx('latex', testroot='footnotes') |
| 1014 |
def test_reference_in_caption_and_codeblock_in_footnote(app: SphinxTestApp) -> None: |
| 1015 |
app.build(force_all=True) |
| 1016 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1017 |
print(result) |
| 1018 |
print(app.status.getvalue()) |
| 1019 |
print(app.warning.getvalue()) |
| 1020 |
assert ( |
| 1021 |
'\\caption{This is the figure caption with a reference to ' |
| 1022 |
'\\sphinxcite{index:authoryear}.}' |
| 1023 |
) in result |
| 1024 |
assert '\\chapter{The section with a reference to {[}AuthorYear{]}}' in result |
| 1025 |
assert ( |
| 1026 |
'\\sphinxcaption{The table title with a reference to {[}AuthorYear{]}}' |
| 1027 |
) in result |
| 1028 |
assert ( |
| 1029 |
'\\subsubsection*{The rubric title with a reference to {[}AuthorYear{]}}' |
| 1030 |
) in result |
| 1031 |
assert ( |
| 1032 |
'\\chapter{The section with a reference to \\sphinxfootnotemark[6]}\n' |
| 1033 |
'\\label{\\detokenize{index:the-section-with-a-reference-to}}' |
| 1034 |
'%\n\\begin{footnotetext}[6]\\sphinxAtStartFootnote\n' |
| 1035 |
'Footnote in section\n%\n\\end{footnotetext}' |
| 1036 |
) in result |
| 1037 |
assert ( |
| 1038 |
'\\caption{This is the figure caption with a footnote to ' |
| 1039 |
'\\sphinxfootnotemark[8].}\\label{\\detokenize{index:id35}}\\end{figure}\n' |
| 1040 |
'%\n\\begin{footnotetext}[8]\\sphinxAtStartFootnote\n' |
| 1041 |
'Footnote in caption\n%\n\\end{footnotetext}' |
| 1042 |
) in result |
| 1043 |
assert ( |
| 1044 |
'\\sphinxcaption{footnote \\sphinxfootnotemark[9] in ' |
| 1045 |
'caption of normal table}\\label{\\detokenize{index:id36}}' |
| 1046 |
) in result |
| 1047 |
assert ( |
| 1048 |
'\\caption{footnote \\sphinxfootnotemark[10] ' |
| 1049 |
'in caption \\sphinxfootnotemark[11] of longtable\\strut}' |
| 1050 |
) in result |
| 1051 |
assert ( |
| 1052 |
'\\endlastfoot\n\\sphinxtableatstartofbodyhook\n%\n' |
| 1053 |
'\\begin{footnotetext}[10]\\sphinxAtStartFootnote\n' |
| 1054 |
'Foot note in longtable\n%\n\\end{footnotetext}\\ignorespaces %\n' |
| 1055 |
'\\begin{footnotetext}[11]\\sphinxAtStartFootnote\n' |
| 1056 |
'Second footnote in caption of longtable\n' |
| 1057 |
) in result |
| 1058 |
assert ( |
| 1059 |
'This is a reference to the code\\sphinxhyphen{}block in the footnote:\n' |
| 1060 |
'{\\hyperref[\\detokenize{index:codeblockinfootnote}]' |
| 1061 |
'{\\sphinxcrossref{\\DUrole{std}{\\DUrole{std-ref}' |
| 1062 |
'{I am in a footnote}}}}}' |
| 1063 |
) in result |
| 1064 |
assert ( |
| 1065 |
'&\\begin{varwidth}[t]{\\sphinxcolwidth{1}{2}}\n' |
| 1066 |
'\\sphinxAtStartPar\nThis is one more footnote with some code in it %\n' |
| 1067 |
'\\begin{footnote}[12]\\sphinxAtStartFootnote\n' |
| 1068 |
'Third footnote in longtable\n' |
| 1069 |
) in result |
| 1070 |
assert ( |
| 1071 |
'\\end{sphinxVerbatim}\n%\n\\end{footnote}.\n' |
| 1072 |
'\\sphinxbeforeendvarwidth\n\\end{varwidth}%\n\\\\' |
| 1073 |
) in result |
| 1074 |
assert '\\begin{sphinxVerbatim}[commandchars=\\\\\\{\\}]' in result |
| 1075 |
|
| 1076 |
|
| 1077 |
@pytest.mark.sphinx('latex', testroot='footnotes') |
| 1078 |
def test_footnote_referred_multiple_times(app: SphinxTestApp) -> None: |
| 1079 |
app.build(force_all=True) |
| 1080 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1081 |
print(result) |
| 1082 |
print(app.status.getvalue()) |
| 1083 |
print(app.warning.getvalue()) |
| 1084 |
|
| 1085 |
assert ( |
| 1086 |
'Explicitly numbered footnote: %\n' |
| 1087 |
'\\begin{footnote}[100]' |
| 1088 |
'\\sphinxAtStartFootnote\nNumbered footnote\n%\n' |
| 1089 |
'\\end{footnote} \\sphinxfootnotemark[100]\n' |
| 1090 |
) in result |
| 1091 |
assert ( |
| 1092 |
'Named footnote: %\n' |
| 1093 |
'\\begin{footnote}[13]' |
| 1094 |
'\\sphinxAtStartFootnote\nNamed footnote\n%\n' |
| 1095 |
'\\end{footnote} \\sphinxfootnotemark[13]\n' |
| 1096 |
) in result |
| 1097 |
|
| 1098 |
|
| 1099 |
@pytest.mark.sphinx( |
| 1100 |
'latex', |
| 1101 |
testroot='footnotes', |
| 1102 |
confoverrides={'latex_show_urls': 'inline'}, |
| 1103 |
) |
| 1104 |
def test_latex_show_urls_is_inline(app: SphinxTestApp) -> None: |
| 1105 |
app.build(force_all=True) |
| 1106 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1107 |
print(result) |
| 1108 |
print(app.status.getvalue()) |
| 1109 |
print(app.warning.getvalue()) |
| 1110 |
assert ( |
| 1111 |
'Same footnote number %\n' |
| 1112 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1113 |
'footnote in bar\n%\n\\end{footnote} in bar.rst' |
| 1114 |
) in result |
| 1115 |
assert ( |
| 1116 |
'Auto footnote number %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1117 |
'footnote in baz\n%\n\\end{footnote} in baz.rst' |
| 1118 |
) in result |
| 1119 |
assert ( |
| 1120 |
'\\phantomsection\\label{\\detokenize{index:id38}}' |
| 1121 |
'{\\hyperref[\\detokenize{index:the-section' |
| 1122 |
'-with-a-reference-to-authoryear}]' |
| 1123 |
'{\\sphinxcrossref{The section with a reference to ' |
| 1124 |
'\\sphinxcite{index:authoryear}}}}' |
| 1125 |
) in result |
| 1126 |
assert ( |
| 1127 |
'\\phantomsection\\label{\\detokenize{index:id39}}' |
| 1128 |
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]' |
| 1129 |
'{\\sphinxcrossref{The section with a reference to }}}' |
| 1130 |
) in result |
| 1131 |
assert ( |
| 1132 |
'First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n' |
| 1133 |
'First\n%\n\\end{footnote}' |
| 1134 |
) in result |
| 1135 |
assert ( |
| 1136 |
'Second footnote: %\n' |
| 1137 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1138 |
'Second\n%\n\\end{footnote}\n' |
| 1139 |
) in result |
| 1140 |
assert ( |
| 1141 |
'\\sphinxhref{https://sphinx-doc.org/}{Sphinx} (https://sphinx\\sphinxhyphen{}doc.org/)' |
| 1142 |
) in result |
| 1143 |
assert ( |
| 1144 |
'Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n' |
| 1145 |
'Third \\sphinxfootnotemark[4]\n%\n\\end{footnote}%\n' |
| 1146 |
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n' |
| 1147 |
'Footnote inside footnote\n%\n\\end{footnotetext}\\ignorespaces' |
| 1148 |
) in result |
| 1149 |
assert ( |
| 1150 |
'Fourth footnote: %\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n' |
| 1151 |
'Fourth\n%\n\\end{footnote}\n' |
| 1152 |
) in result |
| 1153 |
assert ( |
| 1154 |
'\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde} ' |
| 1155 |
'(https://sphinx\\sphinxhyphen{}doc.org/\\textasciitilde{}test/)' |
| 1156 |
) in result |
| 1157 |
assert ( |
| 1158 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term} ' |
| 1159 |
'(https://sphinx\\sphinxhyphen{}doc.org/)}\n' |
| 1160 |
'\\sphinxAtStartPar\nDescription' |
| 1161 |
) in result |
| 1162 |
assert ( |
| 1163 |
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n' |
| 1164 |
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n' |
| 1165 |
) in result |
| 1166 |
assert ( |
| 1167 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term} ' |
| 1168 |
'(https://sphinx\\sphinxhyphen{}doc.org/)}\n' |
| 1169 |
'\\sphinxAtStartPar\nDescription' |
| 1170 |
) in result |
| 1171 |
assert ( |
| 1172 |
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n' |
| 1173 |
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n' |
| 1174 |
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces ' |
| 1175 |
'\n\\sphinxAtStartPar\nDescription' |
| 1176 |
) in result |
| 1177 |
assert ( |
| 1178 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist} ' |
| 1179 |
'(https://sphinx\\sphinxhyphen{}doc.org/)}' |
| 1180 |
'\n\\sphinxAtStartPar\nDescription' |
| 1181 |
) in result |
| 1182 |
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result |
| 1183 |
assert ( |
| 1184 |
'\\sphinxhref{mailto:[email protected]}' |
| 1185 |
'{sphinx\\sphinxhyphen{}[email protected]}' |
| 1186 |
) in result |
| 1187 |
assert '\\begin{savenotes}\\begin{fulllineitems}' not in result |
| 1188 |
|
| 1189 |
|
| 1190 |
@pytest.mark.sphinx( |
| 1191 |
'latex', |
| 1192 |
testroot='footnotes', |
| 1193 |
confoverrides={'latex_show_urls': 'footnote'}, |
| 1194 |
) |
| 1195 |
def test_latex_show_urls_is_footnote(app: SphinxTestApp) -> None: |
| 1196 |
app.build(force_all=True) |
| 1197 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1198 |
print(result) |
| 1199 |
print(app.status.getvalue()) |
| 1200 |
print(app.warning.getvalue()) |
| 1201 |
assert ( |
| 1202 |
'Same footnote number %\n' |
| 1203 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1204 |
'footnote in bar\n%\n\\end{footnote} in bar.rst' |
| 1205 |
) in result |
| 1206 |
assert ( |
| 1207 |
'Auto footnote number %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n' |
| 1208 |
'footnote in baz\n%\n\\end{footnote} in baz.rst' |
| 1209 |
) in result |
| 1210 |
assert ( |
| 1211 |
'\\phantomsection\\label{\\detokenize{index:id38}}' |
| 1212 |
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to-authoryear}]' |
| 1213 |
'{\\sphinxcrossref{The section with a reference ' |
| 1214 |
'to \\sphinxcite{index:authoryear}}}}' |
| 1215 |
) in result |
| 1216 |
assert ( |
| 1217 |
'\\phantomsection\\label{\\detokenize{index:id39}}' |
| 1218 |
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]' |
| 1219 |
'{\\sphinxcrossref{The section with a reference to }}}' |
| 1220 |
) in result |
| 1221 |
assert ( |
| 1222 |
'First footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n' |
| 1223 |
'First\n%\n\\end{footnote}' |
| 1224 |
) in result |
| 1225 |
assert ( |
| 1226 |
'Second footnote: %\n' |
| 1227 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1228 |
'Second\n%\n\\end{footnote}' |
| 1229 |
) in result |
| 1230 |
assert ( |
| 1231 |
'\\sphinxhref{https://sphinx-doc.org/}{Sphinx}' |
| 1232 |
'%\n\\begin{footnote}[4]\\sphinxAtStartFootnote\n' |
| 1233 |
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n\\end{footnote}' |
| 1234 |
) in result |
| 1235 |
assert ( |
| 1236 |
'Third footnote: %\n\\begin{footnote}[6]\\sphinxAtStartFootnote\n' |
| 1237 |
'Third \\sphinxfootnotemark[7]\n%\n\\end{footnote}%\n' |
| 1238 |
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n' |
| 1239 |
'Footnote inside footnote\n%\n' |
| 1240 |
'\\end{footnotetext}\\ignorespaces' |
| 1241 |
) in result |
| 1242 |
assert ( |
| 1243 |
'Fourth footnote: %\n\\begin{footnote}[8]\\sphinxAtStartFootnote\n' |
| 1244 |
'Fourth\n%\n\\end{footnote}\n' |
| 1245 |
) in result |
| 1246 |
assert ( |
| 1247 |
'\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde}' |
| 1248 |
'%\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n' |
| 1249 |
'\\sphinxnolinkurl{https://sphinx-doc.org/~test/}\n%\n\\end{footnote}' |
| 1250 |
) in result |
| 1251 |
assert ( |
| 1252 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}' |
| 1253 |
'{URL in term}\\sphinxfootnotemark[10]}%\n' |
| 1254 |
'\\begin{footnotetext}[10]' |
| 1255 |
'\\sphinxAtStartFootnote\n' |
| 1256 |
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n' |
| 1257 |
'\\end{footnotetext}\\ignorespaces \n\\sphinxAtStartPar\nDescription' |
| 1258 |
) in result |
| 1259 |
assert ( |
| 1260 |
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[12]}%\n' |
| 1261 |
'\\begin{footnotetext}[12]' |
| 1262 |
'\\sphinxAtStartFootnote\n' |
| 1263 |
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces ' |
| 1264 |
'\n\\sphinxAtStartPar\nDescription' |
| 1265 |
) in result |
| 1266 |
assert ( |
| 1267 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist}' |
| 1268 |
'\\sphinxfootnotemark[11]}%\n' |
| 1269 |
'\\begin{footnotetext}[11]' |
| 1270 |
'\\sphinxAtStartFootnote\n' |
| 1271 |
'\\sphinxnolinkurl{https://sphinx-doc.org/}\n%\n' |
| 1272 |
'\\end{footnotetext}\\ignorespaces \n\\sphinxAtStartPar\nDescription' |
| 1273 |
) in result |
| 1274 |
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result |
| 1275 |
assert ( |
| 1276 |
'\\sphinxhref{mailto:[email protected]}' |
| 1277 |
'{sphinx\\sphinxhyphen{}[email protected]}\n' |
| 1278 |
) in result |
| 1279 |
assert '\\begin{savenotes}\\begin{fulllineitems}' in result |
| 1280 |
|
| 1281 |
|
| 1282 |
@pytest.mark.sphinx( |
| 1283 |
'latex', |
| 1284 |
testroot='footnotes', |
| 1285 |
confoverrides={'latex_show_urls': 'no'}, |
| 1286 |
) |
| 1287 |
def test_latex_show_urls_is_no(app: SphinxTestApp) -> None: |
| 1288 |
app.build(force_all=True) |
| 1289 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1290 |
print(result) |
| 1291 |
print(app.status.getvalue()) |
| 1292 |
print(app.warning.getvalue()) |
| 1293 |
assert ( |
| 1294 |
'Same footnote number %\n' |
| 1295 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1296 |
'footnote in bar\n%\n\\end{footnote} in bar.rst' |
| 1297 |
) in result |
| 1298 |
assert ( |
| 1299 |
'Auto footnote number %\n\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1300 |
'footnote in baz\n%\n\\end{footnote} in baz.rst' |
| 1301 |
) in result |
| 1302 |
assert ( |
| 1303 |
'\\phantomsection\\label{\\detokenize{index:id38}}' |
| 1304 |
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to-authoryear}]' |
| 1305 |
'{\\sphinxcrossref{The section with a reference ' |
| 1306 |
'to \\sphinxcite{index:authoryear}}}}' |
| 1307 |
) in result |
| 1308 |
assert ( |
| 1309 |
'\\phantomsection\\label{\\detokenize{index:id39}}' |
| 1310 |
'{\\hyperref[\\detokenize{index:the-section-with-a-reference-to}]' |
| 1311 |
'{\\sphinxcrossref{The section with a reference to }}}' |
| 1312 |
) in result |
| 1313 |
assert ( |
| 1314 |
'First footnote: %\n\\begin{footnote}[2]\\sphinxAtStartFootnote\n' |
| 1315 |
'First\n%\n\\end{footnote}' |
| 1316 |
) in result |
| 1317 |
assert ( |
| 1318 |
'Second footnote: %\n' |
| 1319 |
'\\begin{footnote}[1]\\sphinxAtStartFootnote\n' |
| 1320 |
'Second\n%\n\\end{footnote}' |
| 1321 |
) in result |
| 1322 |
assert '\\sphinxhref{https://sphinx-doc.org/}{Sphinx}' in result |
| 1323 |
assert ( |
| 1324 |
'Third footnote: %\n\\begin{footnote}[3]\\sphinxAtStartFootnote\n' |
| 1325 |
'Third \\sphinxfootnotemark[4]\n%\n\\end{footnote}%\n' |
| 1326 |
'\\begin{footnotetext}[4]\\sphinxAtStartFootnote\n' |
| 1327 |
'Footnote inside footnote\n%\n\\end{footnotetext}\\ignorespaces' |
| 1328 |
) in result |
| 1329 |
assert ( |
| 1330 |
'Fourth footnote: %\n\\begin{footnote}[5]\\sphinxAtStartFootnote\n' |
| 1331 |
'Fourth\n%\n\\end{footnote}\n' |
| 1332 |
) in result |
| 1333 |
assert '\\sphinxhref{https://sphinx-doc.org/~test/}{URL including tilde}' in result |
| 1334 |
assert ( |
| 1335 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{URL in term}}\n' |
| 1336 |
'\\sphinxAtStartPar\nDescription' |
| 1337 |
) in result |
| 1338 |
assert ( |
| 1339 |
'\\sphinxlineitem{Footnote in term \\sphinxfootnotemark[7]}%\n' |
| 1340 |
'\\begin{footnotetext}[7]\\sphinxAtStartFootnote\n' |
| 1341 |
'Footnote in term\n%\n\\end{footnotetext}\\ignorespaces ' |
| 1342 |
'\n\\sphinxAtStartPar\nDescription' |
| 1343 |
) in result |
| 1344 |
assert ( |
| 1345 |
'\\sphinxlineitem{\\sphinxhref{https://sphinx-doc.org/}{Term in deflist}}' |
| 1346 |
'\n\\sphinxAtStartPar\nDescription' |
| 1347 |
) in result |
| 1348 |
assert '\\sphinxurl{https://github.com/sphinx-doc/sphinx}\n' in result |
| 1349 |
assert ( |
| 1350 |
'\\sphinxhref{mailto:[email protected]}' |
| 1351 |
'{sphinx\\sphinxhyphen{}[email protected]}\n' |
| 1352 |
) in result |
| 1353 |
assert '\\begin{savenotes}\\begin{fulllineitems}' not in result |
| 1354 |
|
| 1355 |
|
| 1356 |
@pytest.mark.sphinx( |
| 1357 |
'latex', |
| 1358 |
testroot='footnotes', |
| 1359 |
confoverrides={ |
| 1360 |
'latex_show_urls': 'footnote', |
| 1361 |
'rst_prolog': '.. |URL| replace:: `text <https://www.example.com/>`__', |
| 1362 |
}, |
| 1363 |
) |
| 1364 |
def test_latex_show_urls_footnote_and_substitutions(app: SphinxTestApp) -> None: |
| 1365 |
# hyperlinks in substitutions should not effect to make footnotes |
| 1366 |
# See: https://github.com/sphinx-doc/sphinx/issues/4784 |
| 1367 |
test_latex_show_urls_is_footnote(app) |
| 1368 |
|
| 1369 |
|
| 1370 |
@pytest.mark.sphinx('latex', testroot='image-in-section') |
| 1371 |
def test_image_in_section(app: SphinxTestApp) -> None: |
| 1372 |
app.build(force_all=True) |
| 1373 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1374 |
print(result) |
| 1375 |
print(app.status.getvalue()) |
| 1376 |
print(app.warning.getvalue()) |
| 1377 |
assert ( |
| 1378 |
'\\chapter[Test section]{\\lowercase{\\sphinxincludegraphics' |
| 1379 |
'[width=15bp,height=15bp]}{{pic}.png} Test section}' |
| 1380 |
) in result |
| 1381 |
assert ( |
| 1382 |
'\\chapter[Other {[}blah{]} section]{Other {[}blah{]} ' |
| 1383 |
'\\lowercase{\\sphinxincludegraphics[width=15bp,height=15bp]}' |
| 1384 |
'{{pic}.png} section}' |
| 1385 |
) in result |
| 1386 |
assert '\\chapter{Another section}' in result |
| 1387 |
|
| 1388 |
|
| 1389 |
@pytest.mark.sphinx( |
| 1390 |
'latex', |
| 1391 |
testroot='basic', |
| 1392 |
confoverrides={'latex_logo': 'notfound.jpg'}, |
| 1393 |
) |
| 1394 |
def test_latex_logo_if_not_found(app: SphinxTestApp) -> None: |
| 1395 |
with pytest.raises(SphinxError): |
| 1396 |
app.build(force_all=True) |
| 1397 |
|
| 1398 |
|
| 1399 |
@pytest.mark.sphinx('latex', testroot='toctree-maxdepth') |
| 1400 |
def test_toctree_maxdepth_manual(app: SphinxTestApp) -> None: |
| 1401 |
app.build(force_all=True) |
| 1402 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1403 |
print(result) |
| 1404 |
print(app.status.getvalue()) |
| 1405 |
print(app.warning.getvalue()) |
| 1406 |
assert '\\setcounter{tocdepth}{1}' in result |
| 1407 |
assert '\\setcounter{secnumdepth}' not in result |
| 1408 |
assert '\\chapter{Foo}' in result |
| 1409 |
|
| 1410 |
|
| 1411 |
@pytest.mark.sphinx( |
| 1412 |
'latex', |
| 1413 |
testroot='toctree-maxdepth', |
| 1414 |
confoverrides={ |
| 1415 |
'latex_documents': [ |
| 1416 |
( |
| 1417 |
'index', |
| 1418 |
'projectnamenotset.tex', |
| 1419 |
'Sphinx Tests Documentation', |
| 1420 |
'Georg Brandl', |
| 1421 |
'howto', |
| 1422 |
), |
| 1423 |
] |
| 1424 |
}, |
| 1425 |
) |
| 1426 |
def test_toctree_maxdepth_howto(app: SphinxTestApp) -> None: |
| 1427 |
app.build(force_all=True) |
| 1428 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1429 |
print(result) |
| 1430 |
print(app.status.getvalue()) |
| 1431 |
print(app.warning.getvalue()) |
| 1432 |
assert '\\setcounter{tocdepth}{2}' in result |
| 1433 |
assert '\\setcounter{secnumdepth}' not in result |
| 1434 |
assert '\\section{Foo}' in result |
| 1435 |
|
| 1436 |
|
| 1437 |
@pytest.mark.sphinx( |
| 1438 |
'latex', |
| 1439 |
testroot='toctree-maxdepth', |
| 1440 |
confoverrides={'root_doc': 'foo'}, |
| 1441 |
) |
| 1442 |
def test_toctree_not_found(app: SphinxTestApp) -> None: |
| 1443 |
app.build(force_all=True) |
| 1444 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1445 |
print(result) |
| 1446 |
print(app.status.getvalue()) |
| 1447 |
print(app.warning.getvalue()) |
| 1448 |
assert '\\setcounter{tocdepth}' not in result |
| 1449 |
assert '\\setcounter{secnumdepth}' not in result |
| 1450 |
assert '\\chapter{Foo A}' in result |
| 1451 |
|
| 1452 |
|
| 1453 |
@pytest.mark.sphinx( |
| 1454 |
'latex', |
| 1455 |
testroot='toctree-maxdepth', |
| 1456 |
confoverrides={'root_doc': 'bar'}, |
| 1457 |
) |
| 1458 |
def test_toctree_without_maxdepth(app: SphinxTestApp) -> None: |
| 1459 |
app.build(force_all=True) |
| 1460 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1461 |
print(result) |
| 1462 |
print(app.status.getvalue()) |
| 1463 |
print(app.warning.getvalue()) |
| 1464 |
assert '\\setcounter{tocdepth}' not in result |
| 1465 |
assert '\\setcounter{secnumdepth}' not in result |
| 1466 |
|
| 1467 |
|
| 1468 |
@pytest.mark.sphinx( |
| 1469 |
'latex', |
| 1470 |
testroot='toctree-maxdepth', |
| 1471 |
confoverrides={'root_doc': 'qux'}, |
| 1472 |
) |
| 1473 |
def test_toctree_with_deeper_maxdepth(app: SphinxTestApp) -> None: |
| 1474 |
app.build(force_all=True) |
| 1475 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1476 |
print(result) |
| 1477 |
print(app.status.getvalue()) |
| 1478 |
print(app.warning.getvalue()) |
| 1479 |
assert '\\setcounter{tocdepth}{3}' in result |
| 1480 |
assert '\\setcounter{secnumdepth}{3}' in result |
| 1481 |
|
| 1482 |
|
| 1483 |
@pytest.mark.sphinx( |
| 1484 |
'latex', |
| 1485 |
testroot='toctree-maxdepth', |
| 1486 |
confoverrides={'latex_toplevel_sectioning': None}, |
| 1487 |
) |
| 1488 |
def test_latex_toplevel_sectioning_is_None(app: SphinxTestApp) -> None: |
| 1489 |
app.build(force_all=True) |
| 1490 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1491 |
print(result) |
| 1492 |
print(app.status.getvalue()) |
| 1493 |
print(app.warning.getvalue()) |
| 1494 |
assert '\\chapter{Foo}' in result |
| 1495 |
|
| 1496 |
|
| 1497 |
@pytest.mark.sphinx( |
| 1498 |
'latex', |
| 1499 |
testroot='toctree-maxdepth', |
| 1500 |
confoverrides={'latex_toplevel_sectioning': 'part'}, |
| 1501 |
) |
| 1502 |
def test_latex_toplevel_sectioning_is_part(app: SphinxTestApp) -> None: |
| 1503 |
app.build(force_all=True) |
| 1504 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1505 |
print(result) |
| 1506 |
print(app.status.getvalue()) |
| 1507 |
print(app.warning.getvalue()) |
| 1508 |
assert '\\part{Foo}' in result |
| 1509 |
assert '\\chapter{Foo A}' in result |
| 1510 |
assert '\\chapter{Foo B}' in result |
| 1511 |
|
| 1512 |
|
| 1513 |
@pytest.mark.sphinx( |
| 1514 |
'latex', |
| 1515 |
testroot='toctree-maxdepth', |
| 1516 |
confoverrides={ |
| 1517 |
'latex_toplevel_sectioning': 'part', |
| 1518 |
'latex_documents': [ |
| 1519 |
( |
| 1520 |
'index', |
| 1521 |
'projectnamenotset.tex', |
| 1522 |
'Sphinx Tests Documentation', |
| 1523 |
'Georg Brandl', |
| 1524 |
'howto', |
| 1525 |
), |
| 1526 |
], |
| 1527 |
}, |
| 1528 |
) |
| 1529 |
def test_latex_toplevel_sectioning_is_part_with_howto(app: SphinxTestApp) -> None: |
| 1530 |
app.build(force_all=True) |
| 1531 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1532 |
print(result) |
| 1533 |
print(app.status.getvalue()) |
| 1534 |
print(app.warning.getvalue()) |
| 1535 |
assert '\\part{Foo}' in result |
| 1536 |
assert '\\section{Foo A}' in result |
| 1537 |
assert '\\section{Foo B}' in result |
| 1538 |
|
| 1539 |
|
| 1540 |
@pytest.mark.sphinx( |
| 1541 |
'latex', |
| 1542 |
testroot='toctree-maxdepth', |
| 1543 |
confoverrides={'latex_toplevel_sectioning': 'chapter'}, |
| 1544 |
) |
| 1545 |
def test_latex_toplevel_sectioning_is_chapter(app: SphinxTestApp) -> None: |
| 1546 |
app.build(force_all=True) |
| 1547 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1548 |
print(result) |
| 1549 |
print(app.status.getvalue()) |
| 1550 |
print(app.warning.getvalue()) |
| 1551 |
assert '\\chapter{Foo}' in result |
| 1552 |
|
| 1553 |
|
| 1554 |
@pytest.mark.sphinx( |
| 1555 |
'latex', |
| 1556 |
testroot='toctree-maxdepth', |
| 1557 |
confoverrides={ |
| 1558 |
'latex_toplevel_sectioning': 'chapter', |
| 1559 |
'latex_documents': [ |
| 1560 |
( |
| 1561 |
'index', |
| 1562 |
'projectnamenotset.tex', |
| 1563 |
'Sphinx Tests Documentation', |
| 1564 |
'Georg Brandl', |
| 1565 |
'howto', |
| 1566 |
), |
| 1567 |
], |
| 1568 |
}, |
| 1569 |
) |
| 1570 |
def test_latex_toplevel_sectioning_is_chapter_with_howto(app: SphinxTestApp) -> None: |
| 1571 |
app.build(force_all=True) |
| 1572 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1573 |
print(result) |
| 1574 |
print(app.status.getvalue()) |
| 1575 |
print(app.warning.getvalue()) |
| 1576 |
assert '\\section{Foo}' in result |
| 1577 |
|
| 1578 |
|
| 1579 |
@pytest.mark.sphinx( |
| 1580 |
'latex', |
| 1581 |
testroot='toctree-maxdepth', |
| 1582 |
confoverrides={'latex_toplevel_sectioning': 'section'}, |
| 1583 |
) |
| 1584 |
def test_latex_toplevel_sectioning_is_section(app: SphinxTestApp) -> None: |
| 1585 |
app.build(force_all=True) |
| 1586 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1587 |
print(result) |
| 1588 |
print(app.status.getvalue()) |
| 1589 |
print(app.warning.getvalue()) |
| 1590 |
assert '\\section{Foo}' in result |
| 1591 |
|
| 1592 |
|
| 1593 |
@skip_if_stylefiles_notfound |
| 1594 |
@pytest.mark.sphinx('latex', testroot='maxlistdepth') |
| 1595 |
def test_maxlistdepth_at_ten(app: SphinxTestApp) -> None: |
| 1596 |
app.build(force_all=True) |
| 1597 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1598 |
print(result) |
| 1599 |
print(app.status.getvalue()) |
| 1600 |
print(app.warning.getvalue()) |
| 1601 |
compile_latex_document(app, 'projectnamenotset.tex') |
| 1602 |
|
| 1603 |
|
| 1604 |
@pytest.mark.sphinx( |
| 1605 |
'latex', |
| 1606 |
testroot='latex-table', |
| 1607 |
confoverrides={'latex_table_style': []}, |
| 1608 |
) |
| 1609 |
@pytest.mark.test_params(shared_result='latex-table') |
| 1610 |
def test_latex_table_tabulars(app: SphinxTestApp) -> None: |
| 1611 |
app.build(force_all=True) |
| 1612 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1613 |
tables = {} |
| 1614 |
for chap in re.split(r'\\(?:section|chapter){', result)[1:]: |
| 1615 |
sectname, _, content = chap.partition('}') |
| 1616 |
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator |
| 1617 |
tables[sectname] = content.strip() |
| 1618 |
|
| 1619 |
def get_expected(name: str) -> str: |
| 1620 |
return ( |
| 1621 |
(app.srcdir / 'expects' / (name + '.tex')) |
| 1622 |
.read_text(encoding='utf8') |
| 1623 |
.strip() |
| 1624 |
) |
| 1625 |
|
| 1626 |
for sectname in ( |
| 1627 |
'simple table', |
| 1628 |
'table having widths option', |
| 1629 |
'tabulary having align option', |
| 1630 |
'tabular having align option', |
| 1631 |
'table with tabularcolumns', |
| 1632 |
'table having three paragraphs cell in first col', |
| 1633 |
'table having caption', |
| 1634 |
'table having verbatim', |
| 1635 |
'table having formerly problematic', |
| 1636 |
'table having widths and formerly problematic', |
| 1637 |
'table having stub columns and formerly problematic', |
| 1638 |
): |
| 1639 |
actual = tables[sectname] |
| 1640 |
expected = get_expected(sectname.replace(' ', '_')) |
| 1641 |
assert actual == expected |
| 1642 |
|
| 1643 |
|
| 1644 |
@pytest.mark.sphinx( |
| 1645 |
'latex', |
| 1646 |
testroot='latex-table', |
| 1647 |
confoverrides={'latex_table_style': []}, |
| 1648 |
) |
| 1649 |
@pytest.mark.test_params(shared_result='latex-table') |
| 1650 |
def test_latex_table_longtable(app: SphinxTestApp) -> None: |
| 1651 |
app.build(force_all=True) |
| 1652 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1653 |
tables = {} |
| 1654 |
for chap in re.split(r'\\(?:section|chapter){', result)[1:]: |
| 1655 |
sectname, _, content = chap.partition('}') |
| 1656 |
content = re.sub(r'\\sphinxstepscope', '', content) # filter a separator |
| 1657 |
tables[sectname] = content.strip() |
| 1658 |
|
| 1659 |
def get_expected(name: str) -> str: |
| 1660 |
return ( |
| 1661 |
(app.srcdir / 'expects' / (name + '.tex')) |
| 1662 |
.read_text(encoding='utf8') |
| 1663 |
.strip() |
| 1664 |
) |
| 1665 |
|
| 1666 |
for sectname in ( |
| 1667 |
'longtable', |
| 1668 |
'longtable having widths option', |
| 1669 |
'longtable having align option', |
| 1670 |
'longtable with tabularcolumns', |
| 1671 |
'longtable having caption', |
| 1672 |
'longtable having verbatim', |
| 1673 |
'longtable having formerly problematic', |
| 1674 |
'longtable having widths and formerly problematic', |
| 1675 |
'longtable having stub columns and formerly problematic', |
| 1676 |
'longtable with multirow cell near page footer', |
| 1677 |
): |
| 1678 |
actual = tables[sectname] |
| 1679 |
expected = get_expected(sectname.replace(' ', '_')) |
| 1680 |
assert actual == expected |
| 1681 |
|
| 1682 |
|
| 1683 |
@pytest.mark.sphinx( |
| 1684 |
'latex', |
| 1685 |
testroot='latex-table', |
| 1686 |
confoverrides={'latex_table_style': []}, |
| 1687 |
) |
| 1688 |
@pytest.mark.test_params(shared_result='latex-table') |
| 1689 |
def test_latex_table_complex_tables(app: SphinxTestApp) -> None: |
| 1690 |
app.build(force_all=True) |
| 1691 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1692 |
tables = {} |
| 1693 |
for chap in re.split(r'\\(?:section|renewcommand){', result)[1:]: |
| 1694 |
sectname, _, content = chap.partition('}') |
| 1695 |
tables[sectname] = content.strip() |
| 1696 |
|
| 1697 |
def get_expected(name: str) -> str: |
| 1698 |
return ( |
| 1699 |
(app.srcdir / 'expects' / (name + '.tex')) |
| 1700 |
.read_text(encoding='utf8') |
| 1701 |
.strip() |
| 1702 |
) |
| 1703 |
|
| 1704 |
for sectname in ( |
| 1705 |
'grid table', |
| 1706 |
'grid table with tabularcolumns', |
| 1707 |
'complex spanning cell', |
| 1708 |
): |
| 1709 |
actual = tables[sectname] |
| 1710 |
expected = get_expected(sectname.replace(' ', '_')) |
| 1711 |
assert actual == expected |
| 1712 |
|
| 1713 |
|
| 1714 |
@pytest.mark.sphinx('latex', testroot='latex-table') |
| 1715 |
def test_latex_table_with_booktabs_and_colorrows(app: SphinxTestApp) -> None: |
| 1716 |
app.build(force_all=True) |
| 1717 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1718 |
assert r'\PassOptionsToPackage{booktabs}{sphinx}' in result |
| 1719 |
assert r'\PassOptionsToPackage{colorrows}{sphinx}' in result |
| 1720 |
# tabularcolumns |
| 1721 |
assert r'\begin{longtable}{|c|c|}' in result |
| 1722 |
# class: standard |
| 1723 |
assert r'\begin{tabulary}{\linewidth}[t]{|T|T|T|T|T|}' in result |
| 1724 |
assert r'\begin{longtable}{ll}' in result |
| 1725 |
assert r'\begin{tabular}[t]{*{2}{\X{1}{2}}}' in result |
| 1726 |
assert r'\begin{tabular}[t]{\X{30}{100}\X{70}{100}}' in result |
| 1727 |
|
| 1728 |
|
| 1729 |
@pytest.mark.sphinx( |
| 1730 |
'latex', |
| 1731 |
testroot='latex-table', |
| 1732 |
confoverrides={'templates_path': ['_mytemplates/latex']}, |
| 1733 |
) |
| 1734 |
def test_latex_table_custom_template_caseA(app: SphinxTestApp) -> None: |
| 1735 |
app.build(force_all=True) |
| 1736 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1737 |
assert 'SALUT LES COPAINS' in result |
| 1738 |
assert 'AU REVOIR, KANIGGETS' in result |
| 1739 |
|
| 1740 |
|
| 1741 |
@pytest.mark.sphinx( |
| 1742 |
'latex', |
| 1743 |
testroot='latex-table', |
| 1744 |
confoverrides={'templates_path': ['_mytemplates']}, |
| 1745 |
) |
| 1746 |
def test_latex_table_custom_template_caseB(app: SphinxTestApp) -> None: |
| 1747 |
app.build(force_all=True) |
| 1748 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1749 |
assert 'SALUT LES COPAINS' not in result |
| 1750 |
|
| 1751 |
|
| 1752 |
@pytest.mark.sphinx('latex', testroot='latex-table') |
| 1753 |
@pytest.mark.test_params(shared_result='latex-table') |
| 1754 |
def test_latex_table_custom_template_caseC(app: SphinxTestApp) -> None: |
| 1755 |
app.build(force_all=True) |
| 1756 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1757 |
assert 'SALUT LES COPAINS' not in result |
| 1758 |
|
| 1759 |
|
| 1760 |
@pytest.mark.sphinx('latex', testroot='directives-raw') |
| 1761 |
def test_latex_raw_directive(app: SphinxTestApp) -> None: |
| 1762 |
app.build(force_all=True) |
| 1763 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1764 |
|
| 1765 |
# standard case |
| 1766 |
assert 'standalone raw directive (HTML)' not in result |
| 1767 |
assert ( |
| 1768 |
'\\label{\\detokenize{index:id1}}\nstandalone raw directive (LaTeX)' |
| 1769 |
) in result |
| 1770 |
|
| 1771 |
# with substitution |
| 1772 |
assert 'HTML: abc ghi' in result |
| 1773 |
assert 'LaTeX: abc def ghi' in result |
| 1774 |
|
| 1775 |
|
| 1776 |
@pytest.mark.sphinx('latex', testroot='images') |
| 1777 |
def test_latex_images(app: SphinxTestApp) -> None: |
| 1778 |
with http_server(RemoteImageHandler, port=7777): |
| 1779 |
app.build(force_all=True) |
| 1780 |
|
| 1781 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1782 |
|
| 1783 |
# images are copied |
| 1784 |
assert '\\sphinxincludegraphics{{sphinx}.png}' in result |
| 1785 |
assert (app.outdir / 'sphinx.png').exists() |
| 1786 |
|
| 1787 |
# not found images |
| 1788 |
assert '\\sphinxincludegraphics{{NOT_EXIST}.PNG}' not in result |
| 1789 |
assert ( |
| 1790 |
'WARNING: Could not fetch remote image: ' |
| 1791 |
'http://localhost:7777/NOT_EXIST.PNG [404]' |
| 1792 |
) in app.warning.getvalue() |
| 1793 |
|
| 1794 |
# an image having target |
| 1795 |
assert ( |
| 1796 |
'\\sphinxhref{https://www.sphinx-doc.org/}' |
| 1797 |
'{\\sphinxincludegraphics{{rimg}.png}}\n\n' |
| 1798 |
) in result |
| 1799 |
|
| 1800 |
# a centered image having target |
| 1801 |
assert ( |
| 1802 |
'\\sphinxhref{https://www.python.org/}{{\\hspace*{\\fill}' |
| 1803 |
'\\sphinxincludegraphics{{rimg}.png}\\hspace*{\\fill}}}\n\n' |
| 1804 |
) in result |
| 1805 |
|
| 1806 |
|
| 1807 |
@pytest.mark.sphinx('latex', testroot='latex-index') |
| 1808 |
def test_latex_index(app: SphinxTestApp) -> None: |
| 1809 |
app.build(force_all=True) |
| 1810 |
|
| 1811 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1812 |
assert ( |
| 1813 |
'A \\index{famous@\\spxentry{famous}}famous ' |
| 1814 |
'\\index{equation@\\spxentry{equation}}equation:\n' |
| 1815 |
) in result |
| 1816 |
assert ( |
| 1817 |
'\n\\index{Einstein@\\spxentry{Einstein}}' |
| 1818 |
'\\index{relativity@\\spxentry{relativity}}' |
| 1819 |
'\\ignorespaces \n\\sphinxAtStartPar\nand' |
| 1820 |
) in result |
| 1821 |
assert ( |
| 1822 |
'\n\\index{main \\sphinxleftcurlybrace{}@\\spxentry{' |
| 1823 |
'main \\sphinxleftcurlybrace{}}}\\ignorespaces ' |
| 1824 |
) in result |
| 1825 |
|
| 1826 |
|
| 1827 |
@pytest.mark.sphinx('latex', testroot='latex-equations') |
| 1828 |
def test_latex_equations(app: SphinxTestApp) -> None: |
| 1829 |
app.build(force_all=True) |
| 1830 |
|
| 1831 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1832 |
expected = ( |
| 1833 |
(app.srcdir / 'expects' / 'latex-equations.tex') |
| 1834 |
.read_text(encoding='utf8') |
| 1835 |
.strip() |
| 1836 |
) |
| 1837 |
|
| 1838 |
assert expected in result |
| 1839 |
|
| 1840 |
|
| 1841 |
@pytest.mark.sphinx('latex', testroot='image-in-parsed-literal') |
| 1842 |
def test_latex_image_in_parsed_literal(app: SphinxTestApp) -> None: |
| 1843 |
app.build(force_all=True) |
| 1844 |
|
| 1845 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1846 |
assert ( |
| 1847 |
'{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}' |
| 1848 |
'{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}' |
| 1849 |
'}AFTER' |
| 1850 |
) in result |
| 1851 |
|
| 1852 |
|
| 1853 |
@pytest.mark.sphinx('latex', testroot='nested-enumerated-list') |
| 1854 |
def test_latex_nested_enumerated_list(app: SphinxTestApp) -> None: |
| 1855 |
app.build(force_all=True) |
| 1856 |
|
| 1857 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1858 |
assert ( |
| 1859 |
'\\sphinxsetlistlabels{\\arabic}{enumi}{enumii}{}{.}%\n\\setcounter{enumi}{4}\n' |
| 1860 |
) in result |
| 1861 |
assert ( |
| 1862 |
'\\sphinxsetlistlabels{\\alph}{enumii}{enumiii}{}{.}%\n' |
| 1863 |
'\\setcounter{enumii}{3}\n' |
| 1864 |
) in result |
| 1865 |
assert ( |
| 1866 |
'\\sphinxsetlistlabels{\\arabic}{enumiii}{enumiv}{}{)}%\n' |
| 1867 |
'\\setcounter{enumiii}{9}\n' |
| 1868 |
) in result |
| 1869 |
assert ( |
| 1870 |
'\\sphinxsetlistlabels{\\arabic}{enumiv}{enumv}{(}{)}%\n' |
| 1871 |
'\\setcounter{enumiv}{23}\n' |
| 1872 |
) in result |
| 1873 |
assert ( |
| 1874 |
'\\sphinxsetlistlabels{\\roman}{enumii}{enumiii}{}{.}%\n' |
| 1875 |
'\\setcounter{enumii}{2}\n' |
| 1876 |
) in result |
| 1877 |
|
| 1878 |
|
| 1879 |
@pytest.mark.sphinx('latex', testroot='footnotes') |
| 1880 |
def test_latex_thebibliography(app: SphinxTestApp) -> None: |
| 1881 |
app.build(force_all=True) |
| 1882 |
|
| 1883 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1884 |
print(result) |
| 1885 |
assert ( |
| 1886 |
'\\begin{sphinxthebibliography}{AuthorYe}\n' |
| 1887 |
'\\bibitem[AuthorYear]{index:authoryear}\n\\sphinxAtStartPar\n' |
| 1888 |
'Author, Title, Year\n' |
| 1889 |
'\\end{sphinxthebibliography}\n' |
| 1890 |
) in result |
| 1891 |
assert '\\sphinxcite{index:authoryear}' in result |
| 1892 |
|
| 1893 |
|
| 1894 |
@pytest.mark.sphinx('latex', testroot='glossary') |
| 1895 |
def test_latex_glossary(app: SphinxTestApp) -> None: |
| 1896 |
app.build(force_all=True) |
| 1897 |
|
| 1898 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1899 |
assert ( |
| 1900 |
r'\sphinxlineitem{ähnlich\index{ähnlich@\spxentry{ähnlich}|spxpagem}' |
| 1901 |
r'\phantomsection' |
| 1902 |
r'\label{\detokenize{index:term-ahnlich}}}' |
| 1903 |
) in result |
| 1904 |
assert ( |
| 1905 |
r'\sphinxlineitem{boson\index{boson@\spxentry{boson}|spxpagem}\phantomsection' |
| 1906 |
r'\label{\detokenize{index:term-boson}}}' |
| 1907 |
) in result |
| 1908 |
assert ( |
| 1909 |
r'\sphinxlineitem{\sphinxstyleemphasis{fermion}' |
| 1910 |
r'\index{fermion@\spxentry{fermion}|spxpagem}' |
| 1911 |
r'\phantomsection' |
| 1912 |
r'\label{\detokenize{index:term-fermion}}}' |
| 1913 |
) in result |
| 1914 |
assert ( |
| 1915 |
r'\sphinxlineitem{tauon\index{tauon@\spxentry{tauon}|spxpagem}\phantomsection' |
| 1916 |
r'\label{\detokenize{index:term-tauon}}}' |
| 1917 |
r'\sphinxlineitem{myon\index{myon@\spxentry{myon}|spxpagem}\phantomsection' |
| 1918 |
r'\label{\detokenize{index:term-myon}}}' |
| 1919 |
r'\sphinxlineitem{electron\index{electron@\spxentry{electron}|spxpagem}\phantomsection' |
| 1920 |
r'\label{\detokenize{index:term-electron}}}' |
| 1921 |
) in result |
| 1922 |
assert ( |
| 1923 |
r'\sphinxlineitem{über\index{über@\spxentry{über}|spxpagem}\phantomsection' |
| 1924 |
r'\label{\detokenize{index:term-uber}}}' |
| 1925 |
) in result |
| 1926 |
|
| 1927 |
|
| 1928 |
@pytest.mark.sphinx('latex', testroot='latex-labels') |
| 1929 |
def test_latex_labels(app: SphinxTestApp) -> None: |
| 1930 |
app.build(force_all=True) |
| 1931 |
|
| 1932 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 1933 |
|
| 1934 |
# ref: docutils r10151 |
| 1935 |
if docutils.__version_info__[:2] < (0, 22): |
| 1936 |
figure_id, table_id = 'id1', 'id2' |
| 1937 |
else: |
| 1938 |
figure_id, table_id = 'id2', 'id3' |
| 1939 |
|
| 1940 |
# figures |
| 1941 |
assert ( |
| 1942 |
r'\caption{labeled figure}' |
| 1943 |
r'\label{\detokenize{index:' + figure_id + '}}' |
| 1944 |
r'\label{\detokenize{index:figure2}}' |
| 1945 |
r'\label{\detokenize{index:figure1}}' |
| 1946 |
r'\end{figure}' |
| 1947 |
) in result |
| 1948 |
assert ( |
| 1949 |
r'\caption{labeled figure}' |
| 1950 |
'\\label{\\detokenize{index:figure3}}\n' |
| 1951 |
'\\begin{sphinxlegend}\n\\sphinxAtStartPar\n' |
| 1952 |
'with a legend\n\\end{sphinxlegend}\n' |
| 1953 |
r'\end{figure}' |
| 1954 |
) in result |
| 1955 |
|
| 1956 |
# code-blocks |
| 1957 |
assert ( |
| 1958 |
r'\def\sphinxLiteralBlockLabel{' |
| 1959 |
r'\label{\detokenize{index:codeblock2}}' |
| 1960 |
r'\label{\detokenize{index:codeblock1}}}' |
| 1961 |
) in result |
| 1962 |
assert ( |
| 1963 |
r'\def\sphinxLiteralBlockLabel{\label{\detokenize{index:codeblock3}}}' |
| 1964 |
) in result |
| 1965 |
|
| 1966 |
# tables |
| 1967 |
assert ( |
| 1968 |
r'\sphinxcaption{table caption}' |
| 1969 |
r'\label{\detokenize{index:' + table_id + '}}' |
| 1970 |
r'\label{\detokenize{index:table2}}' |
| 1971 |
r'\label{\detokenize{index:table1}}' |
| 1972 |
) in result |
| 1973 |
assert r'\sphinxcaption{table caption}\label{\detokenize{index:table3}}' in result |
| 1974 |
|
| 1975 |
# sections |
| 1976 |
assert ( |
| 1977 |
'\\chapter{subsection}\n' |
| 1978 |
r'\label{\detokenize{index:subsection}}' |
| 1979 |
r'\label{\detokenize{index:section2}}' |
| 1980 |
r'\label{\detokenize{index:section1}}' |
| 1981 |
) in result |
| 1982 |
assert ( |
| 1983 |
'\\section{subsubsection}\n' |
| 1984 |
r'\label{\detokenize{index:subsubsection}}' |
| 1985 |
r'\label{\detokenize{index:section3}}' |
| 1986 |
) in result |
| 1987 |
assert ( |
| 1988 |
'\\subsection{otherdoc}\n' |
| 1989 |
r'\label{\detokenize{otherdoc:otherdoc}}' |
| 1990 |
r'\label{\detokenize{otherdoc::doc}}' |
| 1991 |
) in result |
| 1992 |
|
| 1993 |
# Named hyperlink reference with embedded alias reference |
| 1994 |
# See: https://github.com/sphinx-doc/sphinx/issues/5948 |
| 1995 |
assert result.count(r'\label{\detokenize{index:section1}}') == 1 |
| 1996 |
# https://github.com/sphinx-doc/sphinx/issues/13609 |
| 1997 |
assert r'\phantomsection\label{\detokenize{index:id' not in result |
| 1998 |
|
| 1999 |
|
| 2000 |
@pytest.mark.sphinx('latex', testroot='latex-figure-in-admonition') |
| 2001 |
def test_latex_figure_in_admonition(app: SphinxTestApp) -> None: |
| 2002 |
app.build(force_all=True) |
| 2003 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2004 |
assert 'tabulary' not in result |
| 2005 |
for type in ('caution', 'note', 'seealso', 'todo'): |
| 2006 |
assert f'{type} directive.\n\n\\begin{{figure}}[H]' in result |
| 2007 |
|
| 2008 |
|
| 2009 |
def test_default_latex_documents() -> None: |
| 2010 |
from sphinx.util import texescape |
| 2011 |
|
| 2012 |
texescape.init() |
| 2013 |
config = Config({ |
| 2014 |
'root_doc': 'index', |
| 2015 |
'project': 'STASI™ Documentation', |
| 2016 |
'author': "Wolfgang Schäuble & G'Beckstein.", |
| 2017 |
}) |
| 2018 |
config.add('latex_engine', None, 'env', (str, NoneType)) |
| 2019 |
config.add('latex_theme', 'manual', 'env', (str,)) |
| 2020 |
expected = [ |
| 2021 |
( |
| 2022 |
'index', |
| 2023 |
'stasi.tex', |
| 2024 |
'STASI™ Documentation', |
| 2025 |
r'Wolfgang Schäuble \& G\textquotesingle{}Beckstein.\@{}', |
| 2026 |
'manual', |
| 2027 |
) |
| 2028 |
] |
| 2029 |
assert default_latex_documents(config) == expected |
| 2030 |
|
| 2031 |
|
| 2032 |
@skip_if_requested |
| 2033 |
@skip_if_stylefiles_notfound |
| 2034 |
@pytest.mark.sphinx('latex', testroot='latex-includegraphics') |
| 2035 |
def test_includegraphics_oversized(app: SphinxTestApp) -> None: |
| 2036 |
app.build(force_all=True) |
| 2037 |
print(app.status.getvalue()) |
| 2038 |
print(app.warning.getvalue()) |
| 2039 |
compile_latex_document(app) |
| 2040 |
|
| 2041 |
|
| 2042 |
@pytest.mark.sphinx('latex', testroot='index_on_title') |
| 2043 |
def test_index_on_title(app: SphinxTestApp) -> None: |
| 2044 |
app.build(force_all=True) |
| 2045 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2046 |
assert ( |
| 2047 |
'\\chapter{Test for index in top level title}\n' |
| 2048 |
'\\label{\\detokenize{contents:test-for-index-in-top-level-title}}' |
| 2049 |
'\\index{index@\\spxentry{index}}\n' |
| 2050 |
) in result |
| 2051 |
|
| 2052 |
|
| 2053 |
@pytest.mark.sphinx( |
| 2054 |
'latex', |
| 2055 |
testroot='latex-unicode', |
| 2056 |
confoverrides={'latex_engine': 'pdflatex'}, |
| 2057 |
) |
| 2058 |
def test_texescape_for_non_unicode_supported_engine(app: SphinxTestApp) -> None: |
| 2059 |
app.build(force_all=True) |
| 2060 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2061 |
print(result) |
| 2062 |
assert 'script small e: e' in result |
| 2063 |
assert 'double struck italic small i: i' in result |
| 2064 |
assert r'superscript: \(\sp{\text{0}}\), \(\sp{\text{1}}\)' in result |
| 2065 |
assert r'subscript: \(\sb{\text{0}}\), \(\sb{\text{1}}\)' in result |
| 2066 |
|
| 2067 |
|
| 2068 |
@pytest.mark.sphinx( |
| 2069 |
'latex', |
| 2070 |
testroot='latex-unicode', |
| 2071 |
confoverrides={'latex_engine': 'xelatex'}, |
| 2072 |
) |
| 2073 |
def test_texescape_for_unicode_supported_engine(app: SphinxTestApp) -> None: |
| 2074 |
app.build(force_all=True) |
| 2075 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2076 |
print(result) |
| 2077 |
assert 'script small e: e' in result |
| 2078 |
assert 'double struck italic small i: i' in result |
| 2079 |
assert 'superscript: ⁰, ¹' in result |
| 2080 |
assert 'subscript: ₀, ₁' in result |
| 2081 |
|
| 2082 |
|
| 2083 |
@pytest.mark.sphinx( |
| 2084 |
'latex', |
| 2085 |
testroot='basic', |
| 2086 |
confoverrides={'latex_elements': {'extrapackages': r'\usepackage{foo}'}}, |
| 2087 |
) |
| 2088 |
def test_latex_elements_extrapackages(app: SphinxTestApp) -> None: |
| 2089 |
app.build(force_all=True) |
| 2090 |
result = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 2091 |
assert r'\usepackage{foo}' in result |
| 2092 |
|
| 2093 |
|
| 2094 |
@pytest.mark.sphinx('latex', testroot='nested-tables') |
| 2095 |
def test_latex_nested_tables(app: SphinxTestApp) -> None: |
| 2096 |
app.build(force_all=True) |
| 2097 |
assert app.warning.getvalue() == '' |
| 2098 |
|
| 2099 |
|
| 2100 |
@pytest.mark.sphinx('latex', testroot='latex-container') |
| 2101 |
def test_latex_container(app: SphinxTestApp) -> None: |
| 2102 |
app.build(force_all=True) |
| 2103 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2104 |
assert r'\begin{sphinxuseclass}{classname}' in result |
| 2105 |
assert r'\end{sphinxuseclass}' in result |
| 2106 |
|
| 2107 |
|
| 2108 |
@pytest.mark.sphinx('latex', testroot='reST-code-role') |
| 2109 |
def test_latex_code_role(app: SphinxTestApp) -> None: |
| 2110 |
if tuple(map(int, pygments.__version__.split('.')[:2])) >= (2, 19): |
| 2111 |
sp = r'\PYG{+w}{ }' |
| 2112 |
else: |
| 2113 |
sp = ' ' |
| 2114 |
|
| 2115 |
app.build() |
| 2116 |
content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2117 |
|
| 2118 |
common_content = ( |
| 2119 |
r'\PYG{k}{def}' + sp + r'\PYG{n+nf}{foo}' |
| 2120 |
r'\PYG{p}{(}' |
| 2121 |
r'\PYG{l+m+mi}{1} ' |
| 2122 |
r'\PYG{o}{+} ' |
| 2123 |
r'\PYG{l+m+mi}{2} ' |
| 2124 |
r'\PYG{o}{+} ' |
| 2125 |
r'\PYG{k+kc}{None} ' |
| 2126 |
r'\PYG{o}{+} ' |
| 2127 |
r'\PYG{l+s+s2}{\PYGZdq{}}' |
| 2128 |
r'\PYG{l+s+s2}{abc}' |
| 2129 |
r'\PYG{l+s+s2}{\PYGZdq{}}' |
| 2130 |
r'\PYG{p}{)}' |
| 2131 |
r'\PYG{p}{:} ' |
| 2132 |
r'\PYG{k}{pass}' |
| 2133 |
) |
| 2134 |
assert ( |
| 2135 |
'Inline \\sphinxcode{\\sphinxupquote{%\n' + common_content + '%\n}} code block' |
| 2136 |
) in content |
| 2137 |
assert ( |
| 2138 |
r'\begin{sphinxVerbatim}[commandchars=\\\{\}]' |
| 2139 |
'\n' + common_content + '\n' + r'\end{sphinxVerbatim}' |
| 2140 |
) in content |
| 2141 |
|
| 2142 |
|
| 2143 |
@pytest.mark.usefixtures('_http_teapot') |
| 2144 |
@pytest.mark.sphinx('latex', testroot='images') |
| 2145 |
def test_copy_images(app: SphinxTestApp) -> None: |
| 2146 |
app.build() |
| 2147 |
|
| 2148 |
test_dir = Path(app.outdir) |
| 2149 |
images = { |
| 2150 |
image.name |
| 2151 |
for image in test_dir.rglob('*') |
| 2152 |
if image.suffix in {'.gif', '.pdf', '.png', '.svg'} |
| 2153 |
} |
| 2154 |
images.discard('sphinx.png') |
| 2155 |
assert images == { |
| 2156 |
'ba30773957c3fe046897111afd65a80b81cad089.png', # latex: image from data:image/png URI in source |
| 2157 |
'img.pdf', |
| 2158 |
'rimg.png', |
| 2159 |
'testimäge.png', |
| 2160 |
} # fmt: skip |
| 2161 |
|
| 2162 |
|
| 2163 |
@pytest.mark.sphinx('latex', testroot='latex-labels-before-module') |
| 2164 |
def test_duplicated_labels_before_module(app: SphinxTestApp) -> None: |
| 2165 |
app.build() |
| 2166 |
content: str = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2167 |
|
| 2168 |
pattern = ( |
| 2169 |
r'\\phantomsection\\label\{\\detokenize\{index:label-(?:auto-)?\d+[a-z]*}}' |
| 2170 |
) |
| 2171 |
# labels found in the TeX output |
| 2172 |
output_labels = frozenset(match.group() for match in re.finditer(pattern, content)) |
| 2173 |
# labels that have been tested and occurring exactly once in the output |
| 2174 |
tested_labels = set() |
| 2175 |
|
| 2176 |
# iterate over the (explicit) labels in the corresponding index.rst |
| 2177 |
for rst_label_name in ( |
| 2178 |
'label_1a', |
| 2179 |
'label_1b', |
| 2180 |
'label_2', |
| 2181 |
'label_3', |
| 2182 |
'label_auto_1a', |
| 2183 |
'label_auto_1b', |
| 2184 |
'label_auto_2', |
| 2185 |
'label_auto_3', |
| 2186 |
): |
| 2187 |
tex_label_name = 'index:' + rst_label_name.replace('_', '-') |
| 2188 |
tex_label_code = r'\phantomsection\label{\detokenize{%s}}' % tex_label_name |
| 2189 |
assert content.count(tex_label_code) == 1, ( |
| 2190 |
f'duplicated label: {tex_label_name!r}' |
| 2191 |
) |
| 2192 |
tested_labels.add(tex_label_code) |
| 2193 |
|
| 2194 |
# ensure that we did not forget any label to check |
| 2195 |
# and if so, report them nicely in case of failure |
| 2196 |
assert sorted(tested_labels) == sorted(output_labels) |
| 2197 |
|
| 2198 |
|
| 2199 |
@pytest.mark.sphinx( |
| 2200 |
'latex', |
| 2201 |
testroot='domain-py-python_maximum_signature_line_length', |
| 2202 |
confoverrides={'python_maximum_signature_line_length': 23}, |
| 2203 |
) |
| 2204 |
def test_one_parameter_per_line(app: SphinxTestApp) -> None: |
| 2205 |
app.build(force_all=True) |
| 2206 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2207 |
|
| 2208 |
# signature of 23 characters is too short to trigger one-param-per-line mark-up |
| 2209 |
assert ( |
| 2210 |
'\\pysiglinewithargsret\n' |
| 2211 |
'{\\sphinxbfcode{\\sphinxupquote{hello}}}\n' |
| 2212 |
'{\\sphinxparam{' in result |
| 2213 |
) |
| 2214 |
|
| 2215 |
assert ( |
| 2216 |
'\\pysigwithonelineperarg\n' |
| 2217 |
'{\\sphinxbfcode{\\sphinxupquote{foo}}}\n' |
| 2218 |
'{\\sphinxoptional{\\sphinxparam{' in result |
| 2219 |
) |
| 2220 |
assert r'\sphinxparam{\DUrole{n}{f}}\sphinxparamcomma' in result |
| 2221 |
|
| 2222 |
# generic_arg[T] |
| 2223 |
assert ( |
| 2224 |
'\\pysiglinewithargsretwithtypelist\n' |
| 2225 |
'{\\sphinxbfcode{\\sphinxupquote{generic\\_arg}}}\n' |
| 2226 |
'{\\sphinxtypeparam{\\DUrole{n}{T}}}\n' |
| 2227 |
'{}\n' |
| 2228 |
'{}\n' in result |
| 2229 |
) |
| 2230 |
|
| 2231 |
# generic_foo[T]() |
| 2232 |
assert ( |
| 2233 |
'\\pysiglinewithargsretwithtypelist\n' |
| 2234 |
'{\\sphinxbfcode{\\sphinxupquote{generic\\_foo}}}\n' |
| 2235 |
'{\\sphinxtypeparam{\\DUrole{n}{T}}}\n' |
| 2236 |
'{}\n' |
| 2237 |
'{}\n' in result |
| 2238 |
) |
| 2239 |
|
| 2240 |
# generic_bar[T](x: list[T]) |
| 2241 |
assert ( |
| 2242 |
'\\pysigwithonelineperargwithtypelist\n' |
| 2243 |
'{\\sphinxbfcode{\\sphinxupquote{generic\\_bar}}}\n' |
| 2244 |
'{\\sphinxtypeparam{' in result |
| 2245 |
) |
| 2246 |
|
| 2247 |
# generic_ret[R]() -> R |
| 2248 |
assert ( |
| 2249 |
'\\pysiglinewithargsretwithtypelist\n' |
| 2250 |
'{\\sphinxbfcode{\\sphinxupquote{generic\\_ret}}}\n' |
| 2251 |
'{\\sphinxtypeparam{\\DUrole{n}{R}}}\n' |
| 2252 |
'{}\n' |
| 2253 |
'{{ $\\rightarrow$ R}}\n' in result |
| 2254 |
) |
| 2255 |
|
| 2256 |
# MyGenericClass[X] |
| 2257 |
assert ( |
| 2258 |
'\\pysiglinewithargsretwithtypelist\n' |
| 2259 |
'{\\sphinxbfcode{\\sphinxupquote{\\DUrole{k}{class}\\DUrole{w}{ }}}' |
| 2260 |
'\\sphinxbfcode{\\sphinxupquote{MyGenericClass}}}\n' |
| 2261 |
'{\\sphinxtypeparam{\\DUrole{n}{X}}}\n' |
| 2262 |
'{}\n' |
| 2263 |
'{}\n' in result |
| 2264 |
) |
| 2265 |
|
| 2266 |
# MyList[T](list[T]) |
| 2267 |
assert ( |
| 2268 |
'\\pysiglinewithargsretwithtypelist\n' |
| 2269 |
'{\\sphinxbfcode{\\sphinxupquote{\\DUrole{k}{class}\\DUrole{w}{ }}}' |
| 2270 |
'\\sphinxbfcode{\\sphinxupquote{MyList}}}\n' |
| 2271 |
'{\\sphinxtypeparam{\\DUrole{n}{T}}}\n' |
| 2272 |
'{\\sphinxparam{list{[}T{]}}}\n' |
| 2273 |
'{}\n' in result |
| 2274 |
) |
| 2275 |
|
| 2276 |
|
| 2277 |
@pytest.mark.sphinx( |
| 2278 |
'latex', |
| 2279 |
testroot='domain-py-python_maximum_signature_line_length', |
| 2280 |
confoverrides={ |
| 2281 |
'python_maximum_signature_line_length': 23, |
| 2282 |
'python_trailing_comma_in_multi_line_signatures': False, |
| 2283 |
}, |
| 2284 |
) |
| 2285 |
def test_one_parameter_per_line_without_trailing_comma(app: SphinxTestApp) -> None: |
| 2286 |
app.build(force_all=True) |
| 2287 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2288 |
|
| 2289 |
assert r'\sphinxparam{\DUrole{n}{f}}\sphinxparamcomma' not in result |
| 2290 |
assert r'\sphinxparam{\DUrole{n}{f}}}}' in result |
| 2291 |
|
| 2292 |
|
| 2293 |
@pytest.mark.sphinx('latex', testroot='markup-rubric') |
| 2294 |
def test_latex_rubric(app: SphinxTestApp) -> None: |
| 2295 |
app.build() |
| 2296 |
content = (app.outdir / 'test.tex').read_text(encoding='utf8') |
| 2297 |
assert r'\subsubsection*{This is a rubric}' in content |
| 2298 |
assert r'\subsection*{A rubric with a heading level 2}' in content |
| 2299 |
|
| 2300 |
|
| 2301 |
@pytest.mark.sphinx('latex', testroot='latex-contents-topic-sidebar') |
| 2302 |
def test_latex_contents_topic_sidebar(app: SphinxTestApp) -> None: |
| 2303 |
app.build() |
| 2304 |
result = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8') |
| 2305 |
|
| 2306 |
assert '\\begin{sphinxcontents}\n\\sphinxstylecontentstitle{Contents}\n' in result |
| 2307 |
|
| 2308 |
assert ( |
| 2309 |
'\\begin{sphinxtopic}\n' |
| 2310 |
'\\sphinxstyletopictitle{Title of topic}\n' |
| 2311 |
'\n' |
| 2312 |
'\\sphinxAtStartPar\n' |
| 2313 |
'text of topic\n' |
| 2314 |
'\\end{sphinxtopic}\n' |
| 2315 |
) in result |
| 2316 |
|
| 2317 |
assert ( |
| 2318 |
'\\begin{sphinxsidebar}\n' |
| 2319 |
'\\sphinxstylesidebartitle{Title of sidebar}\n' |
| 2320 |
'\\sphinxstylesidebarsubtitle{sub\\sphinxhyphen{}title}\n' |
| 2321 |
'\n' |
| 2322 |
'\\sphinxAtStartPar\n' |
| 2323 |
'text of sidebar\n' |
| 2324 |
'\\end{sphinxsidebar}\n' |
| 2325 |
) in result |