From e6069cf762dca43f6d6d529eea6249d6e832dd9f Mon Sep 17 00:00:00 2001
From: milde
Date: Fri, 12 Apr 2024 09:51:10 +0000
Subject: [PATCH] Prevent test failure due no Pillow or Pillow version above
10.3.
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit
Skip tests requiring PIL (Pillow) if it is unavailable.
(Hopefully) fix expected output: Pillow versions above 10.3 seem to report the absolute path.
Thanks to Michał Górny for report and analysis [bugs:485].
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@9641 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
---
.../test/test_writers/test_html5_polyglot_parts.py | 102 ++++++++++++++-------
1 file changed, 69 insertions(+), 33 deletions(-)
diff --git a/docutils/test/test_writers/test_html5_polyglot_parts.py b/docutils/test/test_writers/test_html5_polyglot_parts.py
index 0ee3a4977..71ad58f1f 100644
--- a/docutils/test/test_writers/test_html5_polyglot_parts.py
+++ b/docutils/test/test_writers/test_html5_polyglot_parts.py
@@ -25,7 +25,9 @@ if __name__ == '__main__':
import docutils
import docutils.core
+from docutils.parsers.rst.directives.images import PIL
from docutils.utils.code_analyzer import with_pygments
+
if with_pygments:
import pygments
_pv = re.match(r'^([0-9]+)\.([0-9]*)', pygments.__version__)
@@ -36,6 +38,14 @@ if with_pygments:
ROOT_PREFIX = (Path(__file__).parent.parent/'functional'/'input').as_posix()
DATA_ROOT = os.path.abspath(os.path.join(__file__, '..', '..', 'data'))
+# Pillow reports the absolute path since version 10.3.0 (cf. [bugs: 485])
+PIL_NOT_FOUND_PATH = 'dummy.png'
+try:
+ if PIL and (tuple(int(i) for i in PIL.__version__.split('.')) >= (10, 3)):
+ PIL_NOT_FOUND_PATH = Path('dummy.png').resolve()
+except: # noqa: E722
+ PIL = None
+
class Html5WriterPublishPartsTestCase(unittest.TestCase):
"""Test case for HTML writer via the publish_parts interface."""
@@ -636,27 +646,73 @@ EOF
}],
])
+
totest['system_messages'] = ({'stylesheet_path': '',
'embed_stylesheet': False,
'math_output': 'mathml',
'warning_stream': '',
}, [
["""\
-.. image:: dummy.png
- :scale: 100%
+.. image:: https://dummy.png
+ :loading: embed
+""",
+{'fragment': """\
+
+
+""",
+}],
+[f"""\
+.. image:: {DATA_ROOT}/circle-broken.svg
:loading: embed
+""",
+{'fragment': f"""\
+
-.. image:: dummy.mp4
- :scale: 100%
+
+"""
+}],
+[r"""Broken :math:`\sin \my`.
""",
{'fragment': """\
+Broken \\sin \\my.
+
+"""}],
+])
+
+if PIL:
+ totest['system_messages-PIL'] = ({'stylesheet_path': '',
+ 'embed_stylesheet': False,
+ 'math_output': 'mathml',
+ 'warning_stream': '',
+ }, [
+["""\
+.. image:: dummy.png
+ :scale: 100%
+ :loading: embed
+""",
+{'fragment': f"""\
+""",
+}],
+["""\
+.. image:: dummy.mp4
+ :scale: 100%
+""",
+{'fragment': """\
""",
}],
-[f"""\
-.. image:: {DATA_ROOT}/circle-broken.svg
- :loading: embed
-""",
-
-{'fragment': f"""\
-
-
-
-"""
-}],
-[r"""Broken :math:`\sin \my`.
-""",
-{'fragment': """\
-Broken \\sin \\my.
-
-"""}],
])
totest['no_system_messages'] = ({'stylesheet_path': '',
--
2.11.4.GIT