summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_sys.py
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@redhat.com>2018-08-29 09:01:33 (GMT)
committerGitHub <noreply@github.com>2018-08-29 09:01:33 (GMT)
commit0b9ea4b211b24464c7d38f63e45e51c275c52dcd (patch)
treea2935b5f8ae0eaaf627d4536e75cc608df697734 /Lib/test/test_sys.py
parent98c49c6ab239875e35a3c271bc8fabde6c9be804 (diff)
downloadcpython-0b9ea4b211b24464c7d38f63e45e51c275c52dcd.zip
cpython-0b9ea4b211b24464c7d38f63e45e51c275c52dcd.tar.gz
cpython-0b9ea4b211b24464c7d38f63e45e51c275c52dcd.tar.bz2
[3.7] bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986) (GH-8987)
* bpo-34485: stdout uses surrogateescape on POSIX locale (GH-8986) Standard streams like sys.stdout now use the "surrogateescape" error handler, instead of "strict", on the POSIX locale (when the C locale is not coerced and the UTF-8 Mode is disabled). Add tests on sys.stdout.errors with LC_ALL=POSIX. Fix the error handler of standard streams like sys.stdout: PYTHONIOENCODING=":" is now ignored instead of setting the error handler to "strict". (cherry picked from commit 315877dc361d554bec34b4b62c270479ad36a1be)
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r--Lib/test/test_sys.py28
1 files changed, 17 insertions, 11 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 336ae44..27f7590 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -654,10 +654,10 @@ class SysModuleTest(unittest.TestCase):
expected = None
self.check_fsencoding(fs_encoding, expected)
- def c_locale_get_error_handler(self, isolated=False, encoding=None):
+ def c_locale_get_error_handler(self, locale, isolated=False, encoding=None):
# Force the POSIX locale
env = os.environ.copy()
- env["LC_ALL"] = "C"
+ env["LC_ALL"] = locale
env["PYTHONCOERCECLOCALE"] = "0"
code = '\n'.join((
'import sys',
@@ -683,44 +683,50 @@ class SysModuleTest(unittest.TestCase):
stdout, stderr = p.communicate()
return stdout
- def test_c_locale_surrogateescape(self):
- out = self.c_locale_get_error_handler(isolated=True)
+ def check_locale_surrogateescape(self, locale):
+ out = self.c_locale_get_error_handler(locale, isolated=True)
self.assertEqual(out,
'stdin: surrogateescape\n'
'stdout: surrogateescape\n'
'stderr: backslashreplace\n')
# replace the default error handler
- out = self.c_locale_get_error_handler(encoding=':ignore')
+ out = self.c_locale_get_error_handler(locale, encoding=':ignore')
self.assertEqual(out,
'stdin: ignore\n'
'stdout: ignore\n'
'stderr: backslashreplace\n')
# force the encoding
- out = self.c_locale_get_error_handler(encoding='iso8859-1')
+ out = self.c_locale_get_error_handler(locale, encoding='iso8859-1')
self.assertEqual(out,
'stdin: strict\n'
'stdout: strict\n'
'stderr: backslashreplace\n')
- out = self.c_locale_get_error_handler(encoding='iso8859-1:')
+ out = self.c_locale_get_error_handler(locale, encoding='iso8859-1:')
self.assertEqual(out,
'stdin: strict\n'
'stdout: strict\n'
'stderr: backslashreplace\n')
# have no any effect
- out = self.c_locale_get_error_handler(encoding=':')
+ out = self.c_locale_get_error_handler(locale, encoding=':')
self.assertEqual(out,
- 'stdin: strict\n'
- 'stdout: strict\n'
+ 'stdin: surrogateescape\n'
+ 'stdout: surrogateescape\n'
'stderr: backslashreplace\n')
- out = self.c_locale_get_error_handler(encoding='')
+ out = self.c_locale_get_error_handler(locale, encoding='')
self.assertEqual(out,
'stdin: surrogateescape\n'
'stdout: surrogateescape\n'
'stderr: backslashreplace\n')
+ def test_c_locale_surrogateescape(self):
+ self.check_locale_surrogateescape('C')
+
+ def test_posix_locale_surrogateescape(self):
+ self.check_locale_surrogateescape('POSIX')
+
def test_implementation(self):
# This test applies to all implementations equally.