[Python-checkins] r84308 - python/branches/py3k/Lib/test/test_sys.py

victor.stinner python-checkins at python.org
Wed Aug 25 01:05:51 CEST 2010


Author: victor.stinner
Date: Wed Aug 25 01:05:51 2010
New Revision: 84308

Log:
Fix test_sys for FreeBSD, Solaris and Mac OS X

_Py_char2wchar() (mbctowcs) decodes b'\xff' to '\xff' on FreeBSD, Solaris and
Mac OS X, even if the locale is C (and the locale encoding is ASCII). Patch
test_undecodable_code() to support this output and document the two different
kinds of outputs.


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

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	Wed Aug 25 01:05:51 2010
@@ -511,10 +511,23 @@
             stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
             env=env)
         stdout, stderr = p.communicate()
-        pattern = b"Unable to decode the command from the command line:"
+        if p.returncode == 1:
+            # _Py_char2wchar() decoded b'\xff' as '\udcff' (b'\xff' is not
+            # decodable from ASCII) and run_command() failed on
+            # PyUnicode_AsUTF8String(). This is the expected behaviour on
+            # Linux.
+            pattern = b"Unable to decode the command from the command line:"
+        elif p.returncode == 0:
+            # _Py_char2wchar() decoded b'\xff' as '\xff' even if the locale is
+            # C and the locale encoding is ASCII. It occurs on FreeBSD, Solaris
+            # and Mac OS X.
+            pattern = b"'\\xff' "
+            # The output is followed by the encoding name, an alias to ASCII.
+            # Examples: "US-ASCII" or "646" (ISO 646, on Solaris).
+        else:
+            raise AssertionError("Unknown exit code: %s, output=%a" % (p.returncode, stdout))
         if not stdout.startswith(pattern):
             raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
-        self.assertEqual(p.returncode, 1)
 
     def test_sys_flags(self):
         self.assertTrue(sys.flags)


More information about the Python-checkins mailing list