SF.net SVN: docutils:[9641 ] trunk/docutils/test/test _writers/test_html5_polyglo t_parts.py

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9641
          http://sourceforge.net/p/docutils/code/9641
Author:   milde
Date:     2024-04-12 09:51:10 +0000 (Fri, 12 Apr 2024)
Log Message:
-----------
Prevent test failure due no Pillow or Pillow version above 10.3.

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{U+0142} Gorny for report and analysis [bugs:485].

Modified Paths:
--------------
    trunk/docutils/test/test_writers/test_html5_polyglot_parts.py

Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-04-12 09:51:02 UTC (rev 9640)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-04-12 09:51:10 UTC (rev 9641)
@@ -25,7 +25,9 @@
 
 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,7 +38,15 @@
 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,6 +646,7 @@
 }],
 ])
 
+
 totest['system_messages'] = ({'stylesheet_path': '',
                               'embed_stylesheet': False,
                               'math_output': 'mathml',
@@ -642,14 +653,59 @@
                               'warning_stream': '',
                               }, [
 ["""\
+.. image:: https://dummy.png
+   :loading: embed
+""",
+{'fragment': """\
+<img alt="https://dummy.png" src="https://dummy.png" />
+<aside class="system-message">
+<p class="system-message-title">System Message: ERROR/3 \
+(<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
+<p>Cannot embed image &quot;https://dummy.png&quot;:
+  Can only read local images.</p>
+</aside>
+""",
+}],
+[f"""\
+.. image:: {DATA_ROOT}/circle-broken.svg
+   :loading: embed
+""",
+{'fragment': f"""\
+<svg xmlns="http://www.w3.org/2000/svg"
+     viewBox="0 0 10 10">
+  <circle cx="5" cy="5" r="4" fill="lightblue" x/>
+</svg>
+
+<aside class="system-message">
+<p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
+<p>Cannot parse SVG image &quot;{DATA_ROOT}/circle-broken.svg&quot;:
+  not well-formed (invalid token): line 3, column 48</p>
+</aside>
+"""
+}],
+[r"""Broken :math:`\sin \my`.
+""",
+{'fragment': """\
+<p>Broken <span class="math problematic">\\sin \\my</span>.</p>
+<aside class="system-message">
+<p class="system-message-title">System Message: WARNING/2 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
+<p>Unknown LaTeX command &quot;\\my&quot;.</p>
+</aside>
+"""}],
+])
+
+if PIL:
+    totest['system_messages-PIL'] = ({'stylesheet_path': '',
+                                      'embed_stylesheet': False,
+                                      'math_output': 'mathml',
+                                      'warning_stream': '',
+                                      }, [
+["""\
 .. image:: dummy.png
    :scale: 100%
    :loading: embed
-
-.. image:: dummy.mp4
-   :scale: 100%
 """,
-{'fragment': """\
+{'fragment': f"""\
 <img alt="dummy.png" src="dummy.png" />
 <aside class="system-message">
 <p class="system-message-title">System Message: WARNING/2 \
@@ -656,7 +712,7 @@
 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
 <p>Cannot scale image!
   Could not get size from &quot;dummy.png&quot;:
-  [Errno 2] No such file or directory: 'dummy.png'</p>
+  [Errno 2] No such file or directory: '{PIL_NOT_FOUND_PATH}'</p>
 </aside>
 <aside class="system-message">
 <p class="system-message-title">System Message: ERROR/3 \
@@ -664,12 +720,19 @@
 <p>Cannot embed image &quot;dummy.png&quot;:
   [Errno 2] No such file or directory: 'dummy.png'</p>
 </aside>
+""",
+}],
+["""\
+.. image:: dummy.mp4
+   :scale: 100%
+""",
+{'fragment': """\
 <video src="dummy.mp4" title="dummy.mp4">
 <a href="dummy.mp4">dummy.mp4</a>
 </video>
 <aside class="system-message">
 <p class="system-message-title">System Message: WARNING/2 \
-(<span class="docutils literal">&lt;string&gt;</span>, line 5)</p>
+(<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
 <p>Cannot scale image!
   Could not get size from &quot;dummy.mp4&quot;:
   PIL cannot read video images.</p>
@@ -698,33 +761,6 @@
 </aside>
 """,
 }],
-[f"""\
-.. image:: {DATA_ROOT}/circle-broken.svg
-   :loading: embed
-""",
-
-{'fragment': f"""\
-<svg xmlns="http://www.w3.org/2000/svg"
-     viewBox="0 0 10 10">
-  <circle cx="5" cy="5" r="4" fill="lightblue" x/>
-</svg>
-
-<aside class="system-message">
-<p class="system-message-title">System Message: ERROR/3 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
-<p>Cannot parse SVG image &quot;{DATA_ROOT}/circle-broken.svg&quot;:
-  not well-formed (invalid token): line 3, column 48</p>
-</aside>
-"""
-}],
-[r"""Broken :math:`\sin \my`.
-""",
-{'fragment': """\
-<p>Broken <span class="math problematic">\\sin \\my</span>.</p>
-<aside class="system-message">
-<p class="system-message-title">System Message: WARNING/2 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
-<p>Unknown LaTeX command &quot;\\my&quot;.</p>
-</aside>
-"""}],
 ])
 
 totest['no_system_messages'] = ({'stylesheet_path': '',

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.