summaryrefslogtreecommitdiff
path: root/Lib/test
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_subprocess.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_subprocess.py b/Lib/test/test_subprocess.py
index d47e01c1d8..ce53932538 100644
--- a/Lib/test/test_subprocess.py
+++ b/Lib/test/test_subprocess.py
@@ -782,7 +782,7 @@ class POSIXProcessTestCase(BaseTestCase):
self.assertStderrEqual(stderr, b'')
self.assertEqual(p.wait(), -signal.SIGTERM)
- def test_surrogates(self):
+ def test_surrogates_error_message(self):
def prepare():
raise ValueError("surrogate:\uDCff")
@@ -801,6 +801,28 @@ class POSIXProcessTestCase(BaseTestCase):
else:
self.fail("Expected ValueError or RuntimeError")
+ def test_undecodable_env(self):
+ for key, value in (('test', 'abc\uDCFF'), ('test\uDCFF', '42')):
+ value_repr = repr(value).encode("ascii")
+
+ # test str with surrogates
+ script = "import os; print(repr(os.getenv(%s)))" % repr(key)
+ stdout = subprocess.check_output(
+ [sys.executable, "-c", script],
+ env={key: value})
+ stdout = stdout.rstrip(b'\n\r')
+ self.assertEquals(stdout, value_repr)
+
+ # test bytes
+ key = key.encode("ascii", "surrogateescape")
+ value = value.encode("ascii", "surrogateescape")
+ script = "import os; print(repr(os.getenv(%s)))" % repr(key)
+ stdout = subprocess.check_output(
+ [sys.executable, "-c", script],
+ env={key: value})
+ stdout = stdout.rstrip(b'\n\r')
+ self.assertEquals(stdout, value_repr)
+
@unittest.skipUnless(mswindows, "Windows specific tests")
class Win32ProcessTestCase(BaseTestCase):