From: Adam T. <aa-...@us...> - 2024-08-08 20:43:19
|
Sorry, another failure. The root cause of this one seems to be the `uri_parts.scheme not in ('', 'file')` check. On Windows, we get the following, because drives in absolute paths are parsed as URI schemes: ```pycon >>> uri 'S:/Development/docutils/docutils/test/data/circle-broken.svg' >>> urllib.parse.urlparse(uri).scheme 's' ``` We could do something like ``Path(uri).is_file()``, but that has the problems with using pathlib that you mentioned earlier... Full failure below, also on https://github.com/AA-Turner/docutils/actions/runs/10308701375/job/28536730749 ``` ============================================================================================================= FAILURES ============================================================================================================== _________________________________________________________________________ Html5WriterPublishPartsTestCase.test_publish (id="totest['system_messages'][1]") __________________________________________________________________________ self = <test.test_writers.test_html5_polyglot_parts.Html5WriterPublishPartsTestCase testMethod=test_publish> def test_publish(self): if not with_pygments: del totest['syntax_highlight'] writer = 'html5' for name, (settings_overrides, cases) in totest.items(): for casenum, (case_input, case_expected) in enumerate(cases): with self.subTest(id=f'totest[{name!r}][{casenum}]'): parts = docutils.core.publish_parts( source=case_input, writer=writer, settings_overrides={ '_disable_config': True, 'strict_visitor': True, 'stylesheet': '', 'section_self_link': True, **settings_overrides, } ) > self.assertEqual(case_expected, self.format_output(parts)) E AssertionError: {'fragment': '<svg xmlns="http://www.w3.org/2000/svg"\n [410 chars]>\n'} != {'fragment': '<img alt="S:/Development/docutils/docutils[396 chars]>\n'} E + {'fragment': '<img ' E + 'alt="S:/Development/docutils/docutils/test/data/circle-broken.svg" ' E + 'src="S:/Development/docutils/docutils/test/data/circle-broken.svg" ' E - {'fragment': '<svg xmlns="http://www.w3.org/2000/svg"\n' E - ' viewBox="0 0 10 10">\n' E - ' <circle cx="5" cy="5" r="4" fill="lightblue" x/>\n' E - '</svg>\n' E - '\n' E + '/>\n' E ? ++ E E '<aside class="system-message">\n' E '<p class="system-message-title">System Message: ERROR/3 (<span ' E 'class="docutils literal"><string></span>, line 1)</p>\n' E - '<p>Cannot parse SVG image ' E ? ---- ^^^^ E E + '<p>Cannot embed image ' E ? ^^^^ E E '"S:/Development/docutils/docutils/test/data/circle-broken.svg":\n' E - ' not well-formed (invalid token): line 3, column 48</p>\n' E + ' Can only read local images.</p>\n' E '</aside>\n'} docutils\test\test_writers\test_html5_polyglot_parts.py:92: AssertionError ________________________________________________________________________ Html5WriterPublishPartsTestCase.test_publish (id="totest['no_system_messages'][1]") ________________________________________________________________________ self = <test.test_writers.test_html5_polyglot_parts.Html5WriterPublishPartsTestCase testMethod=test_publish> def test_publish(self): if not with_pygments: del totest['syntax_highlight'] writer = 'html5' for name, (settings_overrides, cases) in totest.items(): for casenum, (case_input, case_expected) in enumerate(cases): with self.subTest(id=f'totest[{name!r}][{casenum}]'): parts = docutils.core.publish_parts( source=case_input, writer=writer, settings_overrides={ '_disable_config': True, 'strict_visitor': True, 'stylesheet': '', 'section_self_link': True, **settings_overrides, } ) > self.assertEqual(case_expected, self.format_output(parts)) E AssertionError: {'fragment': '<svg xmlns="http://www.w3.org/2000/svg"\n [85 chars]n\n'} != {'fragment': '<img alt="S:/Development/docutils/docutils[98 chars]>\n'} E + {'fragment': '<img ' E + 'alt="S:/Development/docutils/docutils/test/data/circle-broken.svg" ' E + 'src="S:/Development/docutils/docutils/test/data/circle-broken.svg" ' E - {'fragment': '<svg xmlns="http://www.w3.org/2000/svg"\n' E - ' viewBox="0 0 10 10">\n' E - ' <circle cx="5" cy="5" r="4" fill="lightblue" x/>\n' E - '</svg>\n' E - '\n'} E + '/>\n'} E ? ++ docutils\test\test_writers\test_html5_polyglot_parts.py:92: AssertionError ``` A --- **[bugs:#493] Test failure on Windows with embedded images** **Status:** open **Created:** Wed Aug 07, 2024 02:25 AM UTC by Adam Turner **Last Updated:** Thu Aug 08, 2024 08:38 PM UTC **Owner:** nobody xref [r9785], [r9853], [r9855] Dear @milde, Thank you for the fix to my recent patch. It seems neither my patch nor the fix addressed the root cause of the test failures, as tests have resumed failing on Windows. I believe the following demonstrates the problem: ```pycon >>> import sys; print(sys.platform) win32 >>> import urllib.parse, urllib.request >>> urllib.request.url2pathname('test/data/circle-broken.svg') 'test\\data\\circle-broken.svg' >>> urllib.parse.unquote('test/data/circle-broken.svg') 'test/data/circle-broken.svg' ``` Currently, we use `imagepath = urllib.request.url2pathname(uri_parts.path)`, which converts path separators to their platform-native format. On UNIX, `url2pathname` simply calls `unquote`, but on Windows it handles UNC paths (``\\host\path\``) and escaped drive letters (``///C|/users/``). I don't know what led to using `url2pathname()`, as it is quite specialised (the docstring notes "not recommended for general use"). Is it possible to use the simpler `unquote()` here? For local file paths (e.g. without a ``file:///`` scheme), should we even be using URI parsing? Perhaps we should use proper path handling if there is no URI scheme (i.e. the user has provided a file-path). A --- Sent from sourceforge.net because doc...@li... is subscribed to https://sourceforge.net/p/docutils/bugs/ To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/docutils/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list. |