]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #9425: skip tests if a filename is not encodable
authorVictor Stinner <victor.stinner@haypocalc.com>
Sat, 7 Aug 2010 10:09:35 +0000 (10:09 +0000)
committerVictor Stinner <victor.stinner@haypocalc.com>
Sat, 7 Aug 2010 10:09:35 +0000 (10:09 +0000)
Lib/test/test_import.py
Lib/test/test_sax.py
Lib/test/test_sys.py
Lib/test/test_urllib.py
Lib/test/test_urllib2.py
Lib/test/test_xml_etree.py

index 447c17fb61135beca7bab1930f9b212eb4a693be..11cf5444a96ee284c65329aa922f6956b1187fec 100644 (file)
@@ -291,6 +291,11 @@ class ImportTests(unittest.TestCase):
 
     def test_import_by_filename(self):
         path = os.path.abspath(TESTFN)
+        encoding = sys.getfilesystemencoding()
+        try:
+            path.encode(encoding)
+        except UnicodeEncodeError:
+            self.skipTest('path is not encodable to {}'.format(encoding))
         with self.assertRaises(ImportError) as c:
             __import__(path)
         self.assertEqual("Import by filename is not supported.",
index 9b28b3fa106bac1eba244a8122315c639bb3c378..911e7634c24133e7c1ee4395e58ca99646c2ab66 100644 (file)
@@ -18,6 +18,11 @@ import unittest
 
 TEST_XMLFILE = findfile("test.xml", subdir="xmltestdata")
 TEST_XMLFILE_OUT = findfile("test.xml.out", subdir="xmltestdata")
+try:
+    TEST_XMLFILE.encode("utf8")
+    TEST_XMLFILE_OUT.encode("utf8")
+except UnicodeEncodeError:
+    raise unittest.SkipTest("filename is not encodable to utf8")
 
 ns_uri = "http://www.python.org/xml-ns/saxtest/"
 
index eb5d877283a50f509977d410f79b59981cb31e72..244874d5e1a5eb8dec78c08f72ad580ef7d156f0 100644 (file)
@@ -509,8 +509,10 @@ class SysModuleTest(unittest.TestCase):
         p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE)
         stdout, stderr = p.communicate()
         self.assertEqual(p.returncode, 1)
-        self.assert_(b"UnicodeEncodeError:" in stderr,
-            "%r not in %s" % (b"UniodeEncodeError:", ascii(stderr)))
+        self.assertIn(
+            br"UnicodeEncodeError: 'utf-8' codec can't encode character "
+            br"'\udcff' in position 7: surrogates not allowed",
+            stderr)
 
     def test_sys_flags(self):
         self.assertTrue(sys.flags)
index 98308b6af1c5c15bb707b10a33a39ca7b730108d..2a9102c58247600990dbec0f0679d29f1d3b4d76 100644 (file)
@@ -232,8 +232,12 @@ class urlretrieve_FileTests(unittest.TestCase):
             except: pass
 
     def constructLocalFileUrl(self, filePath):
-        return "file://%s" % urllib.request.pathname2url(
-            os.path.abspath(filePath))
+        filePath = os.path.abspath(filePath)
+        try:
+            filePath.encode("utf8")
+        except UnicodeEncodeError:
+            raise unittest.SkipTest("filePath is not encodable to utf8")
+        return "file://%s" % urllib.request.pathname2url(filePath)
 
     def createNewTempFile(self, data=b""):
         """Creates a new temporary file containing the specified data,
index 4d117c7319759f79dbda922fc5282e0eff508a72..b2f7ea86f6d95cbf30771731d30f7d90fe34bcef 100644 (file)
@@ -597,6 +597,10 @@ class OpenerDirectorTests(unittest.TestCase):
 
 
 def sanepathname2url(path):
+    try:
+        path.encode("utf8")
+    except UnicodeEncodeError:
+        raise unittest.SkipTest("path is not encodable to utf8")
     urlpath = urllib.request.pathname2url(path)
     if os.name == "nt" and urlpath.startswith("///"):
         urlpath = urlpath[2:]
index 249ac6411bd335cc0acc045836c9196013d399c2..e7c8a890e277b41252db2cf2ae3c8f3341efaadd 100644 (file)
@@ -13,6 +13,7 @@
 
 import sys
 import cgi
+import unittest
 
 from test import support
 from test.support import findfile
@@ -20,6 +21,10 @@ from test.support import findfile
 from xml.etree import ElementTree as ET
 
 SIMPLE_XMLFILE = findfile("simple.xml", subdir="xmltestdata")
+try:
+    SIMPLE_XMLFILE.encode("utf8")
+except UnicodeEncodeError:
+    raise unittest.SkipTest("filename is not encodable to utf8")
 SIMPLE_NS_XMLFILE = findfile("simple-ns.xml", subdir="xmltestdata")
 
 SAMPLE_XML = """\