SF.net SVN: docutils:[9785 ] trunk/docutils

aa-turner--- via Docutils-checkins <[email protected]>
Newsgroups gmane.text.docutils.cvs
Message-ID <[email protected]>
Revision: 9785
          http://sourceforge.net/p/docutils/code/9785
Author:   aa-turner
Date:     2024-07-31 02:23:32 +0000 (Wed, 31 Jul 2024)
Log Message:
-----------
Fix tests on Windows

Mostly path separator problems.

Modified Paths:
--------------
    trunk/docutils/docutils/writers/_html_base.py
    trunk/docutils/test/test_CLI.py
    trunk/docutils/test/test_utils/test__init__.py
    trunk/docutils/test/test_writers/test_html5_polyglot_parts.py

Modified: trunk/docutils/docutils/writers/_html_base.py
===================================================================
--- trunk/docutils/docutils/writers/_html_base.py	2024-07-30 23:52:51 UTC (rev 9784)
+++ trunk/docutils/docutils/writers/_html_base.py	2024-07-31 02:23:32 UTC (rev 9785)
@@ -22,7 +22,8 @@
 import os.path
 from pathlib import Path
 import re
-import urllib
+import urllib.parse
+import urllib.request
 import warnings
 import xml.etree.ElementTree as ET  # TODO: lazy import in prepare_svg()?
 
@@ -628,7 +629,7 @@
         if uri_parts.scheme not in ('', 'file'):
             raise ValueError('Can only read local images.')
         imagepath = urllib.request.url2pathname(uri_parts.path)
-        if imagepath.startswith('/'):
+        if imagepath.startswith(('/', '\\')):  # UNIX- or Windows-style
             root_prefix = Path(self.settings.root_prefix)
             imagepath = (root_prefix/imagepath[1:]).as_posix()
         elif not os.path.isabs(imagepath):  # exclude absolute Windows paths

Modified: trunk/docutils/test/test_CLI.py
===================================================================
--- trunk/docutils/test/test_CLI.py	2024-07-30 23:52:51 UTC (rev 9784)
+++ trunk/docutils/test/test_CLI.py	2024-07-31 02:23:32 UTC (rev 9785)
@@ -58,7 +58,8 @@
         sys.stdout = self.orig_stdout
         sys.argv = self.orig_argv
         # restore default locale settings:
-        locale.setlocale(locale.LC_MESSAGES, 'C')
+        if sys.platform != "win32":
+            locale.setlocale(locale.LC_MESSAGES, 'C')
         locale.setlocale(locale.LC_TIME, 'C')
 
     def get_help_text(self, prog, entry_point):

Modified: trunk/docutils/test/test_utils/test__init__.py
===================================================================
--- trunk/docutils/test/test_utils/test__init__.py	2024-07-30 23:52:51 UTC (rev 9784)
+++ trunk/docutils/test/test_utils/test__init__.py	2024-07-31 02:23:32 UTC (rev 9785)
@@ -339,7 +339,7 @@
             source = r'C:\foo\bar\fileA'
         target = os.path.join('eggs', 'fileB')
         self.assertEqual(utils.relative_path(source, target),
-                         os.path.abspath('eggs/fileB'))
+                         os.path.abspath('eggs/fileB').replace('\\', '/'))
         # Correctly process characters outside the ASCII range:
         self.assertEqual(utils.relative_path('spam', 'spam'), '')
         source = os.path.join('häm', 'spam', 'fileA')

Modified: trunk/docutils/test/test_writers/test_html5_polyglot_parts.py
===================================================================
--- trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-07-30 23:52:51 UTC (rev 9784)
+++ trunk/docutils/test/test_writers/test_html5_polyglot_parts.py	2024-07-31 02:23:32 UTC (rev 9785)
@@ -66,6 +66,10 @@
         '</aside>\n')
 
 
+def relpath(path: Path) -> str:
+    return path.relative_to(Path.cwd()).as_posix()
+
+
 class Html5WriterPublishPartsTestCase(unittest.TestCase):
     """Test case for HTML writer via the publish_parts interface."""
 
@@ -542,7 +546,7 @@
 """,
 }],
 [f"""\
-.. include:: {DATA_ROOT}/multiple-term-definition.xml
+.. include:: {relpath(DATA_ROOT / 'multiple-term-definition.xml')}
    :parser: xml
 """,
 {'fragment': """\
@@ -714,7 +718,7 @@
 """,
 }],
 [f"""\
-.. image:: {DATA_ROOT}/circle-broken.svg
+.. image:: {relpath(DATA_ROOT / 'circle-broken.svg')}
    :loading: embed
 """,
 {'fragment': f"""\
@@ -725,7 +729,7 @@
 
 <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;:
+<p>Cannot parse SVG image &quot;{relpath(DATA_ROOT / 'circle-broken.svg')}&quot;:
   not well-formed (invalid token): line 3, column 48</p>
 </aside>
 """
@@ -831,7 +835,7 @@
 """,
 }],
 [f"""\
-.. image:: {DATA_ROOT}/circle-broken.svg
+.. image:: {relpath(DATA_ROOT / 'circle-broken.svg')}
    :loading: embed
 """,
 {'fragment': """\

This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



_______________________________________________
Docutils-checkins mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/docutils-checkins
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.