sphinx/tests/test_builders/test_build_texinfo.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

131 lines
4.8 KiB
Python
Raw Normal View History

2010-09-16 02:19:06 -05:00
"""Test the build process with Texinfo builder with the test root."""
import re
import subprocess
from pathlib import Path
2022-10-17 09:54:59 -05:00
from subprocess import CalledProcessError
2019-02-03 04:33:28 -06:00
from unittest.mock import Mock
2010-09-16 02:19:06 -05:00
import pytest
from sphinx.builders.texinfo import default_texinfo_documents
from sphinx.config import Config
from sphinx.util.docutils import new_document
2018-02-19 07:39:14 -06:00
from sphinx.writers.texinfo import TexinfoTranslator
2010-09-16 02:19:06 -05:00
2016-07-14 09:12:57 -05:00
@pytest.mark.sphinx('texinfo')
2016-07-14 09:12:57 -05:00
def test_texinfo(app, status, warning):
TexinfoTranslator.ignore_missing_images = True
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
result = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
assert ('@anchor{markup doc}@anchor{11}'
'@anchor{markup id1}@anchor{12}'
'@anchor{markup testing-various-markup}@anchor{13}' in result)
2018-12-08 09:35:46 -06:00
assert 'Footnotes' not in result
2010-09-16 02:19:06 -05:00
# now, try to run makeinfo over it
try:
args = ['makeinfo', '--no-split', 'sphinxtests.texi']
2022-10-17 09:54:59 -05:00
subprocess.run(args, capture_output=True, cwd=app.outdir, check=True)
except OSError as exc:
raise pytest.skip.Exception from exc # most likely makeinfo was not found
except CalledProcessError as exc:
print(exc.stdout)
print(exc.stderr)
msg = f'makeinfo exited with return code {exc.retcode}'
raise AssertionError(msg) from exc
@pytest.mark.sphinx('texinfo', testroot='markup-rubric')
def test_texinfo_rubric(app, status, warning):
app.build()
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
assert '@heading This is a rubric' in output
assert '@heading This is a multiline rubric' in output
@pytest.mark.sphinx('texinfo', testroot='markup-citation')
def test_texinfo_citation(app, status, warning):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
assert 'This is a citation ref; @ref{1,,[CITE1]} and @ref{2,,[CITE2]}.' in output
assert ('@anchor{index cite1}@anchor{1}@w{(CITE1)} \n'
'This is a citation\n') in output
assert ('@anchor{index cite2}@anchor{2}@w{(CITE2)} \n'
'This is a multiline citation\n') in output
def test_default_texinfo_documents():
config = Config({'project': 'STASI™ Documentation',
2018-12-15 08:02:28 -06:00
'author': "Wolfgang Schäuble & G'Beckstein"})
expected = [('index', 'stasi', 'STASI™ Documentation',
"Wolfgang Schäuble & G'Beckstein", 'stasi',
'One line description of project', 'Miscellaneous')]
assert default_texinfo_documents(config) == expected
2019-02-03 04:33:28 -06:00
@pytest.mark.sphinx('texinfo')
def test_texinfo_escape_id(app, status, warning):
settings = Mock(title='',
texinfo_dir_entry='',
texinfo_elements={})
document = new_document('', settings)
translator = app.builder.create_translator(document, app.builder)
assert translator.escape_id('Hello world') == 'Hello world'
assert translator.escape_id('Hello world') == 'Hello world'
assert translator.escape_id('Hello Sphinx world') == 'Hello Sphinx world'
assert translator.escape_id('Hello:world') == 'Hello world'
assert translator.escape_id('Hello(world)') == 'Hello world'
assert translator.escape_id('Hello world.') == 'Hello world'
assert translator.escape_id('.') == '.'
@pytest.mark.sphinx('texinfo', testroot='footnotes')
def test_texinfo_footnote(app, status, warning):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
output = (app.outdir / 'python.texi').read_text(encoding='utf8')
assert 'First footnote: @footnote{\nFirst\n}' in output
@pytest.mark.sphinx('texinfo')
def test_texinfo_xrefs(app, status, warning):
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
assert re.search(r'@ref{\w+,,--plugin\.option}', output)
# Now rebuild it without xrefs
app.config.texinfo_cross_references = False
2024-01-16 20:38:46 -06:00
app.build(force_all=True)
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
assert not re.search(r'@ref{\w+,,--plugin\.option}', output)
assert 'Link to perl +p, --ObjC++, --plugin.option, create-auth-token, arg and -j' in output
2021-12-10 19:33:07 -06:00
@pytest.mark.sphinx('texinfo', testroot='root')
def test_texinfo_samp_with_variable(app, status, warning):
app.build()
output = (app.outdir / 'sphinxtests.texi').read_text(encoding='utf8')
assert '@code{@var{variable_only}}' in output
assert '@code{@var{variable} and text}' in output
2021-12-10 19:33:07 -06:00
assert '@code{Show @var{variable} in the middle}' in output
@pytest.mark.sphinx('texinfo', testroot='images')
def test_copy_images(app, status, warning):
app.build()
images_dir = Path(app.outdir) / 'python-figures'
images = {image.name for image in images_dir.rglob('*')}
2023-01-10 08:18:46 -06:00
images.discard('python-logo.png')
assert images == {
'img.png',
'rimg.png',
'testimäge.png',
}