[Python-checkins] cpython (2.7): Fix tests for issue #11159.

serhiy.storchaka python-checkins at python.org
Sat Feb 2 11:20:00 CET 2013


http://hg.python.org/cpython/rev/706218e0facb
changeset:   81919:706218e0facb
branch:      2.7
parent:      81913:52f684a75b08
user:        Serhiy Storchaka <storchaka at gmail.com>
date:        Sat Feb 02 12:16:22 2013 +0200
summary:
  Fix tests for issue #11159.

files:
  Lib/test/test_sax.py |  22 ++++++++++++++++------
  1 files changed, 16 insertions(+), 6 deletions(-)


diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py
--- a/Lib/test/test_sax.py
+++ b/Lib/test/test_sax.py
@@ -14,6 +14,7 @@
 from xml.sax.handler import feature_namespaces
 from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl
 from cStringIO import StringIO
+import os.path
 import shutil
 import test.test_support as support
 from test.test_support import findfile, run_unittest
@@ -22,6 +23,18 @@
 TEST_XMLFILE = findfile("test.xml", subdir="xmltestdata")
 TEST_XMLFILE_OUT = findfile("test.xml.out", subdir="xmltestdata")
 
+supports_unicode_filenames = True
+if not os.path.supports_unicode_filenames:
+    try:
+        support.TESTFN_UNICODE.encode(support.TESTFN_ENCODING)
+    except (AttributeError, UnicodeError, TypeError):
+        # Either the file system encoding is None, or the file name
+        # cannot be encoded in the file system encoding.
+        supports_unicode_filenames = False
+requires_unicode_filenames = unittest.skipUnless(
+        supports_unicode_filenames,
+        'Requires unicode filenames support')
+
 ns_uri = "http://www.python.org/xml-ns/saxtest/"
 
 class XmlTestBase(unittest.TestCase):
@@ -386,8 +399,7 @@
 
         self.assertEqual(result.getvalue(), xml_test_out)
 
-    @unittest.skipUnless(hasattr(support, 'TESTFN_UNICODE'),
-                         'Requires unicode filenames support')
+    @requires_unicode_filenames
     def test_expat_file_unicode(self):
         fname = support.TESTFN_UNICODE
         shutil.copyfile(TEST_XMLFILE, fname)
@@ -541,8 +553,7 @@
 
         self.assertEqual(result.getvalue(), xml_test_out)
 
-    @unittest.skipUnless(hasattr(support, 'TESTFN_UNICODE'),
-                         'Requires unicode filenames support')
+    @requires_unicode_filenames
     def test_expat_inpsource_sysid_unicode(self):
         fname = support.TESTFN_UNICODE
         shutil.copyfile(TEST_XMLFILE, fname)
@@ -630,8 +641,7 @@
         self.assertEqual(parser.getSystemId(), TEST_XMLFILE)
         self.assertEqual(parser.getPublicId(), None)
 
-    @unittest.skipUnless(hasattr(support, 'TESTFN_UNICODE'),
-                         'Requires unicode filenames support')
+    @requires_unicode_filenames
     def test_expat_locator_withinfo_unicode(self):
         fname = support.TESTFN_UNICODE
         shutil.copyfile(TEST_XMLFILE, fname)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list