summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2013-11-19 22:46:06 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2013-11-19 22:46:06 (GMT)
commit5323fb0990862a967b3e0cddddaf20762fd0a4a7 (patch)
treea6b4268a0a7328782e803588cb21c6d98cc7a8f1 /Lib
parent85fe8a645e06d54d9b5dfc24375cc9231bff7e00 (diff)
downloadcpython-5323fb0990862a967b3e0cddddaf20762fd0a4a7.zip
cpython-5323fb0990862a967b3e0cddddaf20762fd0a4a7.tar.gz
cpython-5323fb0990862a967b3e0cddddaf20762fd0a4a7.tar.bz2
Issue #19637: fix test_undecodable_env() of test_subprocess on AIX
On AIX, the C locale encoding uses the ISO-8859-1 encoding, not ASCII.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_subprocess.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index e12f593..54f6482 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -1681,31 +1681,38 @@ class POSIXProcessTestCase(BaseTestCase):
def test_undecodable_env(self):
for key, value in (('test', 'abc\uDCFF'), ('test\uDCFF', '42')):
+ encoded_value = value.encode("ascii", "surrogateescape")
+
# test str with surrogates
script = "import os; print(ascii(os.getenv(%s)))" % repr(key)
env = os.environ.copy()
env[key] = value
- # Use C locale to get ascii for the locale encoding to force
+ # Use C locale to get ASCII for the locale encoding to force
# surrogate-escaping of \xFF in the child process; otherwise it can
# be decoded as-is if the default locale is latin-1.
env['LC_ALL'] = 'C'
+ if sys.platform.startswith("aix"):
+ # On AIX, the C locale uses the Latin1 encoding
+ decoded_value = encoded_value.decode("latin1", "surrogateescape")
+ else:
+ # On other UNIXes, the C locale uses the ASCII encoding
+ decoded_value = value
stdout = subprocess.check_output(
[sys.executable, "-c", script],
env=env)
stdout = stdout.rstrip(b'\n\r')
- self.assertEqual(stdout.decode('ascii'), ascii(value))
+ self.assertEqual(stdout.decode('ascii'), ascii(decoded_value))
# test bytes
key = key.encode("ascii", "surrogateescape")
- value = value.encode("ascii", "surrogateescape")
script = "import os; print(ascii(os.getenvb(%s)))" % repr(key)
env = os.environ.copy()
- env[key] = value
+ env[key] = encoded_value
stdout = subprocess.check_output(
[sys.executable, "-c", script],
env=env)
stdout = stdout.rstrip(b'\n\r')
- self.assertEqual(stdout.decode('ascii'), ascii(value))
+ self.assertEqual(stdout.decode('ascii'), ascii(encoded_value))
def test_bytes_program(self):
abs_program = os.fsencode(sys.executable)