Skip to content

Commit

Permalink
Add unit test for issue sphinx-doc#11110 as fixed by sphinx-doc#11113
Browse files Browse the repository at this point in the history
  • Loading branch information
jfbu committed Apr 3, 2023
1 parent e1b15a5 commit 126737c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tests/roots/test-ext-imgmockconverter/1/svgimg.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/roots/test-ext-imgmockconverter/2/svgimg.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions tests/roots/test-ext-imgmockconverter/conf.py
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']
6 changes: 6 additions & 0 deletions tests/roots/test-ext-imgmockconverter/index.rst
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

39 changes: 39 additions & 0 deletions tests/roots/test-ext-imgmockconverter/mocksvgconverter.py
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,
}
17 changes: 17 additions & 0 deletions tests/test_ext_imgmockconverter.py
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()

0 comments on commit 126737c

Please sign in to comment.