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.",
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/"
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)
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,
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:]
import sys
import cgi
+import unittest
from test import support
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 = """\