summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_cmd_line.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-20 21:52:33 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-20 21:52:33 (GMT)
commitf6211eda71085609f0c126e1c9422f10f9637170 (patch)
tree4ad905fa5188d9a4671633ab94997de743ea436d /Lib/test/test_cmd_line.py
parent6722b5f7f1f3774258edacf128a7c3e3163ceee9 (diff)
downloadcpython-f6211eda71085609f0c126e1c9422f10f9637170.zip
cpython-f6211eda71085609f0c126e1c9422f10f9637170.tar.gz
cpython-f6211eda71085609f0c126e1c9422f10f9637170.tar.bz2
Move test_undecodable_code() from test_sys to test_cmd_line
Diffstat (limited to 'Lib/test/test_cmd_line.py')
-rw-r--r--Lib/test/test_cmd_line.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index f7e8f24..35de813 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -108,6 +108,44 @@ class CmdLineTest(unittest.TestCase):
command = "assert(ord('\xe9') == 0xe9)"
assert_python_ok('-c', command)
+ # On Windows, pass bytes to subprocess doesn't test how Python decodes the
+ # command line, but how subprocess does decode bytes to unicode. Python
+ # doesn't decode the command line because Windows provides directly the
+ # arguments as unicode (using wmain() instead of main()).
+ @unittest.skipIf(sys.platform == 'win32',
+ 'Windows has a native unicode API')
+ def test_undecodable_code(self):
+ undecodable = b"\xff"
+ env = os.environ.copy()
+ # Use C locale to get ascii for the locale encoding
+ env['LC_ALL'] = 'C'
+ 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,
+ env=env)
+ stdout, stderr = p.communicate()
+ 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))
+
def test_unbuffered_output(self):
# Test expected operation of the '-u' switch
for stream in ('stdout', 'stderr'):