Skip to content

Commit ebe53a2

Browse files
author
Victor Stinner
committed
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.
1 parent 8515eae commit ebe53a2

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Lib/test/test_sys.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -511,10 +511,23 @@ def test_undecodable_code(self):
511511
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
512512
env=env)
513513
stdout, stderr = p.communicate()
514-
pattern = b"Unable to decode the command from the command line:"
514+
if p.returncode == 1:
515+
# _Py_char2wchar() decoded b'\xff' as '\udcff' (b'\xff' is not
516+
# decodable from ASCII) and run_command() failed on
517+
# PyUnicode_AsUTF8String(). This is the expected behaviour on
518+
# Linux.
519+
pattern = b"Unable to decode the command from the command line:"
520+
elif p.returncode == 0:
521+
# _Py_char2wchar() decoded b'\xff' as '\xff' even if the locale is
522+
# C and the locale encoding is ASCII. It occurs on FreeBSD, Solaris
523+
# and Mac OS X.
524+
pattern = b"'\\xff' "
525+
# The output is followed by the encoding name, an alias to ASCII.
526+
# Examples: "US-ASCII" or "646" (ISO 646, on Solaris).
527+
else:
528+
raise AssertionError("Unknown exit code: %s, output=%a" % (p.returncode, stdout))
515529
if not stdout.startswith(pattern):
516530
raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
517-
self.assertEqual(p.returncode, 1)
518531

519532
def test_sys_flags(self):
520533
self.assertTrue(sys.flags)

0 commit comments

Comments
 (0)