[Python-checkins] r84225 - in python/branches/py3k/Lib/test: support.py test_os.py test_sys.py

victor.stinner python-checkins at python.org
Fri Aug 20 18:52:14 CEST 2010


Author: victor.stinner
Date: Fri Aug 20 18:52:14 2010
New Revision: 84225

Log:
Workaround issue #8611 in test_undecodable_code() of test_sys

Write test.support.workaroundIssue8611() function so it will be easier to
remove this workaround from all tests.


Modified:
   python/branches/py3k/Lib/test/support.py
   python/branches/py3k/Lib/test/test_os.py
   python/branches/py3k/Lib/test/test_sys.py

Modified: python/branches/py3k/Lib/test/support.py
==============================================================================
--- python/branches/py3k/Lib/test/support.py	(original)
+++ python/branches/py3k/Lib/test/support.py	Fri Aug 20 18:52:14 2010
@@ -1277,3 +1277,11 @@
     """
     stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
     return stderr
+
+def workaroundIssue8611():
+    try:
+        sys.executable.encode('ascii')
+    except UnicodeEncodeError:
+        raise unittest.SkipTest(
+            "Issue #8611: Python doesn't support ascii locale encoding "
+            "with an non-ascii path")

Modified: python/branches/py3k/Lib/test/test_os.py
==============================================================================
--- python/branches/py3k/Lib/test/test_os.py	(original)
+++ python/branches/py3k/Lib/test/test_os.py	Fri Aug 20 18:52:14 2010
@@ -1175,15 +1175,12 @@
             self.assertEqual(decoded, repr(unicodefn))
 
         check('utf-8', b'\xc3\xa9\x80', '\xe9\udc80')
-        try:
-            sys.executable.encode("ascii")
-        except UnicodeEncodeError:
-            # Python doesn't start with ASCII locale if its path is not ASCII,
-            # see issue #8611
-            pass
-        else:
-            check('ascii', b'abc\xff', 'abc\udcff')
-            check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
+
+        # Raise SkipTest() if sys.executable is not encodable to ascii
+        support.workaroundIssue8611()
+
+        check('ascii', b'abc\xff', 'abc\udcff')
+        check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
 
 
 def test_main():

Modified: python/branches/py3k/Lib/test/test_sys.py
==============================================================================
--- python/branches/py3k/Lib/test/test_sys.py	(original)
+++ python/branches/py3k/Lib/test/test_sys.py	Fri Aug 20 18:52:14 2010
@@ -496,11 +496,16 @@
         self.assertRaises(TypeError, sys.intern, S("abc"))
 
     def test_undecodable_code(self):
-        non_decodable = b"\xff"
+        # Raise SkipTest() if sys.executable is not encodable to ascii
+        test.support.workaroundIssue8611()
+
+        undecodable = b"\xff"
         env = os.environ.copy()
         env['LANG'] = 'C'
-        code = b'import locale; '
-        code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
+        code = (
+            b'import locale; '
+            b'print(ascii("' + undecodable + b'"), '
+                b'locale.getpreferredencoding())')
         p = subprocess.Popen(
             [sys.executable, "-c", code],
             stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
@@ -587,28 +592,23 @@
                 env=env)
             return output.rstrip().decode('ascii')
 
+        # Raise SkipTest() if sys.executable is not encodable to ascii
+        test.support.workaroundIssue8611()
+
+        # Even in C locale
+        env = os.environ.copy()
+        env['LANG'] = 'C'
         try:
-            sys.executable.encode('ascii')
-        except UnicodeEncodeError:
-            # Python doesn't start with ASCII locale if its path is not ASCII,
-            # see issue #8611
+            del env['PYTHONFSENCODING']
+        except KeyError:
             pass
-        else:
-            # Even in C locale
-            env = os.environ.copy()
-            env['LANG'] = 'C'
-            try:
-                del env['PYTHONFSENCODING']
-            except KeyError:
-                pass
-            self.check_fsencoding(get_fsencoding(env), 'ascii')
-
-            # Filesystem encoding is hardcoded on Windows and Mac OS X
-            for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'):
-                env = os.environ.copy()
-                env['PYTHONFSENCODING'] = encoding
-                self.check_fsencoding(get_fsencoding(env), encoding)
+        self.check_fsencoding(get_fsencoding(env), 'ascii')
 
+        # Filesystem encoding is hardcoded on Windows and Mac OS X
+        for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'):
+            env = os.environ.copy()
+            env['PYTHONFSENCODING'] = encoding
+            self.check_fsencoding(get_fsencoding(env), encoding)
 
     def test_setfilesystemencoding(self):
         old = sys.getfilesystemencoding()


More information about the Python-checkins mailing list