summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-05-21 23:45:42 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-05-21 23:45:42 (GMT)
commit7126dbc867e99e675ed29037c6b10681dbaa8dc9 (patch)
treeba594287cd7379500874f5d73c1bc4daed133428 /Lib/test/test_sys.py
parent3df439d1a055f616345fe4128c897a9c27c7b671 (diff)
downloadcpython-7126dbc867e99e675ed29037c6b10681dbaa8dc9.zip
cpython-7126dbc867e99e675ed29037c6b10681dbaa8dc9.tar.gz
cpython-7126dbc867e99e675ed29037c6b10681dbaa8dc9.tar.bz2
Issue #3798: sys.exit(message) writes the message to sys.stderr file, instead
of the C file stderr, to use stderr encoding and error handler
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 4fb1d36..2caf09f 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -146,9 +146,9 @@ class SysModuleTest(unittest.TestCase):
"raise SystemExit(47)"])
self.assertEqual(rc, 47)
- def check_exit_message(code, expected):
+ def check_exit_message(code, expected, env=None):
process = subprocess.Popen([sys.executable, "-c", code],
- stderr=subprocess.PIPE)
+ stderr=subprocess.PIPE, env=env)
stdout, stderr = process.communicate()
self.assertEqual(process.returncode, 1)
self.assertTrue(stderr.startswith(expected),
@@ -166,6 +166,14 @@ class SysModuleTest(unittest.TestCase):
r'import sys; sys.exit("surrogates:\uDCFF")',
b"surrogates:\\udcff")
+ # test that the unicode message is encoded to the stderr encoding
+ # instead of the default encoding (utf8)
+ env = os.environ.copy()
+ env['PYTHONIOENCODING'] = 'latin-1'
+ check_exit_message(
+ r'import sys; sys.exit("h\xe9")',
+ b"h\xe9", env=env)
+
def test_getdefaultencoding(self):
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
# can't check more than the type, as the user might have changed it