Debian Codegraph @

tests/test_ext_imgconverter/test_ext_imgconverter.py

raw
1 """Test sphinx.ext.imgconverter extension."""
2
3 from __future__ import annotations
4
5 import subprocess
6 from typing import TYPE_CHECKING
7
8 import pytest
9
10 if TYPE_CHECKING:
11 from sphinx.testing.util import SphinxTestApp
12
13
14 @pytest.fixture
15 def _if_converter_found(app: SphinxTestApp) -> None:
16 image_converter = getattr(app.config, 'image_converter', '')
17 try:
18 if image_converter:
19 # print the image_converter version, to check that the command is available
20 subprocess.run(
21 [image_converter, '-version'],
22 capture_output=True,
23 check=False,
24 )
25 return
26 except OSError: # No such file or directory
27 pass
28
29 pytest.skip('image_converter "%s" is not available' % image_converter)
30
31
32 @pytest.mark.usefixtures('_if_converter_found')
33 @pytest.mark.sphinx('latex', testroot='ext-imgconverter')
34 def test_ext_imgconverter(app: SphinxTestApp) -> None:
35 app.build(force_all=True)
36
37 content = (app.outdir / 'projectnamenotset.tex').read_text(encoding='utf8')
38
39 # supported image (not converted)
40 assert '\\sphinxincludegraphics{{img}.pdf}' in content
41
42 # non supported image (converted)
43 assert '\\sphinxincludegraphics{{svgimg}.png}' in content
44 assert not (app.outdir / 'svgimg.svg').exists()
45 assert (app.outdir / 'svgimg.png').exists()