diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-03-18 01:18:21 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-03-18 01:18:21 +0100 |
commit | 7143029d4360637aadbd7ddf386ea5c64fb83095 (patch) | |
tree | 618e8173c347bcfe20ea4e073d29e6c419fe702b /Lib/test/test_sys.py | |
parent | 01adf06d375dcc5d2dab7a2d7dc487e0223977c9 (diff) | |
download | cpython-git-7143029d4360637aadbd7ddf386ea5c64fb83095.tar.gz |
Issue #19977: When the ``LC_TYPE`` locale is the POSIX locale (``C`` locale),
:py:data:`sys.stdin` and :py:data:`sys.stdout` are now using the
``surrogateescape`` error handler, instead of the ``strict`` error handler.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 5a9699ff20..f3d0b42be2 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -615,6 +615,50 @@ class SysModuleTest(unittest.TestCase): expected = None self.check_fsencoding(fs_encoding, expected) + @unittest.skipIf(sys.platform == 'win32', + 'test specific to UNIX') + def test_c_locale_surrogateescape(self): + # Force the POSIX locale + env = os.environ.copy() + env["LC_ALL"] = "C" + code = '\n'.join(( + 'import codecs, sys', + 'def dump(name):', + ' std = getattr(sys, name)', + ' encoding = codecs.lookup(std.encoding).name', + ' print("%s: %s:%s" % (name, encoding, std.errors))', + 'dump("stdin")', + 'dump("stdout")', + 'dump("stderr")', + )) + p = subprocess.Popen([sys.executable, "-I", "-c", code], + stdout=subprocess.PIPE, env=env) + out = p.communicate()[0] + self.assertEqual(out, + b'stdin: ascii:surrogateescape\n' + b'stdout: ascii:surrogateescape\n' + b'stderr: ascii:backslashreplace\n') + + # replace the default error handler + env['PYTHONIOENCODING'] = ':strict' + p = subprocess.Popen([sys.executable, "-c", code], + stdout=subprocess.PIPE, env=env) + out = p.communicate()[0] + self.assertEqual(out, + b'stdin: ascii:strict\n' + b'stdout: ascii:strict\n' + b'stderr: ascii:backslashreplace\n') + + # force the encoding + env['PYTHONIOENCODING'] = 'iso8859-1' + p = subprocess.Popen([sys.executable, "-c", code], + stdout=subprocess.PIPE, env=env) + out = p.communicate()[0] + self.assertEqual(out, + b'stdin: iso8859-1:surrogateescape\n' + b'stdout: iso8859-1:surrogateescape\n' + b'stderr: iso8859-1:backslashreplace\n') + def test_implementation(self): # This test applies to all implementations equally. |