Mercurial > cpython-lru_cache-weakref
diff Lib/test/test_subprocess.py @ 60896:8428eaa2d3ad
Issue #8467: Pure Python implementation of subprocess encodes the error message
using surrogatepass error handler to support surrogates in the message
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Fri, 23 Apr 2010 19:28:32 +0000 |
| parents | bb2ca1b63321 |
| children | dc8c8d54504e |
line wrap: on
line diff
--- a/Lib/test/test_subprocess.py Fri Apr 23 13:03:50 2010 +0000 +++ b/Lib/test/test_subprocess.py Fri Apr 23 19:28:32 2010 +0000 @@ -782,6 +782,25 @@ self.assertStderrEqual(stderr, b'') self.assertEqual(p.wait(), -signal.SIGTERM) + def test_surrogates(self): + def prepare(): + raise ValueError("surrogate:\uDCff") + + try: + subprocess.call( + [sys.executable, "-c", "pass"], + preexec_fn=prepare) + except ValueError as err: + # Pure Python implementations keeps the message + self.assertIsNone(subprocess._posixsubprocess) + self.assertEqual(str(err), "surrogate:\uDCff") + except RuntimeError as err: + # _posixsubprocess uses a default message + self.assertIsNotNone(subprocess._posixsubprocess) + self.assertEqual(str(err), "Exception occurred in preexec_fn.") + else: + self.fail("Expected ValueError or RuntimeError") + @unittest.skipUnless(mswindows, "Windows specific tests") class Win32ProcessTestCase(BaseTestCase):
