SF.net SVN: docutils:[9642 ] trunk/docutils/test

milde--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9642
          http://sourceforge.net/p/docutils/code/9642
Author:   milde
Date:     2024-04-15 12:27:35 +0000 (Mon, 15 Apr 2024)
Log Message:
-----------
Avoid dependency of functional tests on PIL/Pillow.

Don't use "scale" image directive option in functional test.

The expected output for the "image" directive with "scale" option
is tested in `test_writers/test_html5_polyglot_parts.py` and
`test_writers/test_html4css1_parts.py` with special-casing
for missing PIL.

Modified Paths:
--------------
    trunk/docutils/test/functional/expected/standalone_rst_html5.html
    trunk/docutils/test/functional/input/data/html5-features.txt
    trunk/docutils/test/test_writers/test_html4css1_parts.py
    trunk/docutils/test/test_writers/test_html5_polyglot_parts.py

Modified: trunk/docutils/test/functional/expected/standalone_rst_html5.html
===================================================================
--- trunk/docutils/test/functional/expected/standalone_rst_html5.html	2024-04-12 09:51:10 UTC (rev 9641)
+++ trunk/docutils/test/functional/expected/standalone_rst_html5.html	2024-04-15 12:27:35 UTC (rev 9642)
@@ -1287,11 +1287,11 @@
 <li><img alt="blue square" class="align-right" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALElEQVR4nO3NMQEAMAjAsDFjvIhHFCbgSwU0kdXvsn96BwAAAAAAAAAAAIsNnEwBk52VRuMAAAAASUVORK5CYII=" />
 <p>Embed images or defer fetching images with the <a class="reference external" href="https://docutils.sourceforge.io/docs/user/config.html#image-loading">image-loading</a> <a class="brackets" href="#footnote-9" id="footnote-reference-22" role="doc-noteref"><span class="fn-bracket">[</span>9<span class="fn-bracket">]</span></a>
 configuration setting or the &quot;loading&quot; option of the &quot;image&quot; directive.</p>
-<img alt="../../../docs/user/rst/images/biohazard.png" class="align-right" loading="lazy" src="../../../docs/user/rst/images/biohazard.png" style="width: 16.0px; height: 16.0px;" />
-<p>Especially with &quot;lazy&quot; loading images, it is strongly recommended to
+<img alt="../../../docs/user/rst/images/biohazard.png" class="align-right" loading="lazy" src="../../../docs/user/rst/images/biohazard.png" style="width: 16px; height: 16px;" />
+<p>Especially with &quot;lazy&quot; loading, it is strongly recommended to
 specify both width and height of the image to prevent content layout
-shifts. (Or use the &quot;scale&quot; option to let the writer insert the size
-determined from the image file.)</p>
+shifts or use the &quot;scale&quot; option to let the writer insert the size
+determined from the image file.</p>
 </li>
 </ul>
 <section id="field-list-rendering">

Modified: trunk/docutils/test/functional/input/data/html5-features.txt
===================================================================
--- trunk/docutils/test/functional/input/data/html5-features.txt	2024-04-12 09:51:10 UTC (rev 9641)
+++ trunk/docutils/test/functional/input/data/html5-features.txt	2024-04-15 12:27:35 UTC (rev 9642)
@@ -47,13 +47,14 @@
 
   .. image:: ../../../docs/user/rst/images/biohazard.png
      :loading: lazy
-     :scale: 100%
+     :width: 16
+     :height: 16
      :align: right
 
-  Especially with "lazy" loading images, it is strongly recommended to
+  Especially with "lazy" loading, it is strongly recommended to
   specify both width and height of the image to prevent content layout
-  shifts. (Or use the "scale" option to let the writer insert the size
-  determined from the image file.)
+  shifts or use the "scale" option to let the writer insert the size
+  determined from the image file.
 
 .. _image-loading:
     https://docutils.sourceforge.io/docs/user/config.html#image-loading

Modified: trunk/docutils/test/test_writers/test_html4css1_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html4css1_parts.py	2024-04-12 09:51:10 UTC (rev 9641)
+++ trunk/docutils/test/test_writers/test_html4css1_parts.py	2024-04-15 12:27:35 UTC (rev 9642)
@@ -23,8 +23,14 @@
 
 import docutils
 import docutils.core
+from docutils.parsers.rst.directives.images import PIL
 
+
 ROOT_PREFIX = (Path(__file__).parent.parent/'functional'/'input').as_posix()
+if PIL:
+    SCALING_OUTPUT = 'style="width: 32.0px; height: 32.0px;" '
+else:
+    SCALING_OUTPUT = ''
 
 
 class Html4WriterPublishPartsTestCase(unittest.TestCase):
@@ -411,9 +417,8 @@
 .. image:: /data/blue%20square.png
    :scale: 100%
 """,
-{'fragment': """\
-<img alt="/data/blue%20square.png" src="/data/blue%20square.png" style="width: 32.0px; height: 32.0px;" />
-""",
+{'fragment': '<img alt="/data/blue%20square.png"'
+             f' src="/data/blue%20square.png" {SCALING_OUTPUT}/>\n',
 }],
 ])
 

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:10 UTC (rev 9641)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-04-15 12:27:35 UTC (rev 9642)
@@ -38,13 +38,31 @@
 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
+# Pillow/PIL is optional:
+if PIL:
+    REQUIRES_PIL = ''
+    ONLY_LOCAL = 'Can only read local images.'
+    DUMMY_PNG_NOT_FOUND = "[Errno 2] No such file or directory: 'dummy.png'"
+    # Pillow reports the absolute path since version 10.3.0 (cf. [bugs: 485])
+    if (tuple(int(i) for i in PIL.__version__.split('.')) >= (10, 3)):
+        DUMMY_PNG_NOT_FOUND = ("[Errno 2] No such file or directory: '%s'"
+                               % Path('dummy.png').resolve())
+    SCALING_OUTPUT = 'style="width: 32.0px; height: 32.0px;" '
+    NO_PIL_SYSTEM_MESSAGE = ''
+else:
+    REQUIRES_PIL = '\n  Requires Python Imaging Library.'
+    ONLY_LOCAL = 'Requires Python Imaging Library.'
+    DUMMY_PNG_NOT_FOUND = 'Requires Python Imaging Library.'
+    SCALING_OUTPUT = ''
+    NO_PIL_SYSTEM_MESSAGE = (
+        '<aside class="system-message">\n'
+        '<p class="system-message-title">System Message:'
+        ' WARNING/2 (<span class="docutils literal">'
+        '&lt;string&gt;</span>, line 1)</p>\n'
+        '<p>Cannot scale image!\n'
+        '  Could not get size from &quot;/data/blue%20square.png&quot;:\n'
+        '  Requires Python Imaging Library.</p>\n'
+        '</aside>\n')
 
 
 class Html5WriterPublishPartsTestCase(unittest.TestCase):
@@ -559,19 +577,25 @@
 totest['root_prefix'] = ({'root_prefix': ROOT_PREFIX,
                           'image_loading': 'embed',
                           'stylesheet_path': '',
-                          'embed_stylesheet': False}, [
+                          'warning_stream': '',
+                          'embed_stylesheet': False
+                          }, [
 ["""\
 .. image:: /data/blue%20square.png
    :scale: 100%
 .. figure:: /data/blue%20square.png
 """,
-{'fragment': """\
-<img alt="/data/blue%20square.png" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALElEQVR4nO3NMQEAMAjAsDFjvIhHFCbgSwU0kdXvsn96BwAAAAAAAAAAAIsNnEwBk52VRuMAAAAASUVORK5CYII="\
- style="width: 32.0px; height: 32.0px;" />
-<figure>
-<img alt="/data/blue%20square.png" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALElEQVR4nO3NMQEAMAjAsDFjvIhHFCbgSwU0kdXvsn96BwAAAAAAAAAAAIsNnEwBk52VRuMAAAAASUVORK5CYII=" />
-</figure>
-""",
+{'fragment': '<img alt="/data/blue%20square.png" src="data:image/png;base64,'
+             'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALElEQVR4nO3NMQ'
+             'EAMAjAsDFjvIhHFCbgSwU0kdXvsn96BwAAAAAAAAAAAIsNnEwBk52VRuMAAAAA'
+             'SUVORK5CYII="'
+             f' {SCALING_OUTPUT}/>\n{NO_PIL_SYSTEM_MESSAGE}'
+             '<figure>\n'
+             '<img alt="/data/blue%20square.png" src="data:image/png;base64,'
+             'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAAALElEQVR4nO3NMQ'
+             'EAMAjAsDFjvIhHFCbgSwU0kdXvsn96BwAAAAAAAAAAAIsNnEwBk52VRuMAAAAA'
+             'SUVORK5CYII=" />\n'
+             '</figure>\n',
 }],
 ])
 
@@ -694,12 +718,11 @@
 """}],
 ])
 
-if PIL:
-    totest['system_messages-PIL'] = ({'stylesheet_path': '',
-                                      'embed_stylesheet': False,
-                                      'math_output': 'mathml',
-                                      'warning_stream': '',
-                                      }, [
+totest['system_messages-PIL'] = ({'stylesheet_path': '',
+                                  'embed_stylesheet': False,
+                                  'math_output': 'mathml',
+                                  'warning_stream': '',
+                                  }, [
 ["""\
 .. image:: dummy.png
    :scale: 100%
@@ -712,7 +735,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: '{PIL_NOT_FOUND_PATH}'</p>
+  {DUMMY_PNG_NOT_FOUND}</p>
 </aside>
 <aside class="system-message">
 <p class="system-message-title">System Message: ERROR/3 \
@@ -726,7 +749,7 @@
 .. image:: dummy.mp4
    :scale: 100%
 """,
-{'fragment': """\
+{'fragment': f"""\
 <video src="dummy.mp4" title="dummy.mp4">
 <a href="dummy.mp4">dummy.mp4</a>
 </video>
@@ -734,7 +757,7 @@
 <p class="system-message-title">System Message: WARNING/2 \
 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
 <p>Cannot scale image!
-  Could not get size from &quot;dummy.mp4&quot;:
+  Could not get size from &quot;dummy.mp4&quot;:{REQUIRES_PIL}
   PIL cannot read video images.</p>
 </aside>
 """,
@@ -744,7 +767,7 @@
    :scale: 100%
    :loading: embed
 """,
-{'fragment': """\
+{'fragment': f"""\
 <img alt="https://dummy.png" src="https://dummy.png" />
 <aside class="system-message">
 <p class="system-message-title">System Message: WARNING/2 \
@@ -751,7 +774,7 @@
 (<span class="docutils literal">&lt;string&gt;</span>, line 1)</p>
 <p>Cannot scale image!
   Could not get size from &quot;https://dummy.png&quot;:
-  Can only read local images.</p>
+  {ONLY_LOCAL}</p>
 </aside>
 <aside class="system-message">
 <p class="system-message-title">System Message: ERROR/3 \

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.