forked from sphinx-doc/sphinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for issue sphinx-doc#11110 as fixed by sphinx-doc#11113
- Loading branch information
Showing
6 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import os | ||
import sys | ||
|
||
sys.path.insert(0, os.path.abspath('.')) | ||
extensions = ['mocksvgconverter'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
test-ext-imgconverter | ||
===================== | ||
|
||
.. image:: ./1/svgimg.svg | ||
.. image:: ./2/svgimg.svg | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
""" | ||
Does foo.svg --> foo.pdf with no change to the file. | ||
""" | ||
|
||
import shutil | ||
|
||
from sphinx.transforms.post_transforms.images import ImageConverter | ||
|
||
if False: | ||
# For type annotation | ||
from typing import Any, Dict # NOQA | ||
|
||
from sphinx.application import Sphinx # NOQA | ||
|
||
class MyConverter(ImageConverter): | ||
conversion_rules = [ | ||
('image/svg+xml', 'application/pdf'), | ||
] | ||
|
||
def is_available(self): | ||
# type: () -> bool | ||
return True | ||
|
||
def convert(self, _from, _to): | ||
# type: (unicode, unicode) -> bool | ||
"""Mock converts the image from SVG to PDF.""" | ||
shutil.copyfile(_from, _to) | ||
return True | ||
|
||
|
||
def setup(app): | ||
# type: (Sphinx) -> Dict[unicode, Any] | ||
app.add_post_transform(MyConverter) | ||
|
||
return { | ||
'version': 'builtin', | ||
'parallel_read_safe': True, | ||
'parallel_write_safe': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Test image converter with identical basenames""" | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.sphinx('latex', testroot='ext-imgmockconverter') | ||
def test_ext_imgmockconverter(app, status, warning): | ||
app.builder.build_all() | ||
|
||
content = (app.outdir / 'python.tex').read_text(encoding='utf8') | ||
|
||
# check identical basenames give distinct files | ||
assert '\\sphinxincludegraphics{{svgimg}.pdf}' in content | ||
assert '\\sphinxincludegraphics{{svgimg1}.pdf}' in content | ||
assert not (app.outdir / 'svgimg.svg').exists() | ||
assert (app.outdir / 'svgimg.pdf').exists() | ||
assert (app.outdir / 'svgimg1.pdf').exists() |