Issue #19977: Enable test_c_locale_surrogateescape() on Windows
Only test the error handler. The encoding is not ASCII on Windows: it may the OEM or ANSI code page.
This commit is contained in:
parent
518e610977
commit
97f17a784a
@ -615,49 +615,52 @@ class SysModuleTest(unittest.TestCase):
|
|||||||
expected = None
|
expected = None
|
||||||
self.check_fsencoding(fs_encoding, expected)
|
self.check_fsencoding(fs_encoding, expected)
|
||||||
|
|
||||||
@unittest.skipIf(sys.platform == 'win32',
|
def c_locale_get_error_handler(self, isolated=False, encoding=None):
|
||||||
'test specific to UNIX')
|
|
||||||
def test_c_locale_surrogateescape(self):
|
|
||||||
# Force the POSIX locale
|
# Force the POSIX locale
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env["LC_ALL"] = "C"
|
env["LC_ALL"] = "C"
|
||||||
code = '\n'.join((
|
code = '\n'.join((
|
||||||
'import codecs, sys',
|
'import sys',
|
||||||
'def dump(name):',
|
'def dump(name):',
|
||||||
' std = getattr(sys, name)',
|
' std = getattr(sys, name)',
|
||||||
' encoding = codecs.lookup(std.encoding).name',
|
' print("%s: %s" % (name, std.errors))',
|
||||||
' print("%s: %s:%s" % (name, encoding, std.errors))',
|
|
||||||
'dump("stdin")',
|
'dump("stdin")',
|
||||||
'dump("stdout")',
|
'dump("stdout")',
|
||||||
'dump("stderr")',
|
'dump("stderr")',
|
||||||
))
|
))
|
||||||
p = subprocess.Popen([sys.executable, "-I", "-c", code],
|
args = [sys.executable, "-c", code]
|
||||||
stdout=subprocess.PIPE, env=env)
|
if isolated:
|
||||||
out = p.communicate()[0]
|
args.append("-I")
|
||||||
|
elif encoding:
|
||||||
|
env['PYTHONIOENCODING'] = encoding
|
||||||
|
p = subprocess.Popen(args,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
env=env,
|
||||||
|
universal_newlines=True)
|
||||||
|
stdout, stderr = p.communicate()
|
||||||
|
return stdout
|
||||||
|
|
||||||
|
def test_c_locale_surrogateescape(self):
|
||||||
|
out = self.c_locale_get_error_handler(isolated=True)
|
||||||
self.assertEqual(out,
|
self.assertEqual(out,
|
||||||
b'stdin: ascii:surrogateescape\n'
|
'stdin: surrogateescape\n'
|
||||||
b'stdout: ascii:surrogateescape\n'
|
'stdout: surrogateescape\n'
|
||||||
b'stderr: ascii:backslashreplace\n')
|
'stderr: backslashreplace\n')
|
||||||
|
|
||||||
# replace the default error handler
|
# replace the default error handler
|
||||||
env['PYTHONIOENCODING'] = ':strict'
|
out = self.c_locale_get_error_handler(encoding=':strict')
|
||||||
p = subprocess.Popen([sys.executable, "-c", code],
|
|
||||||
stdout=subprocess.PIPE, env=env)
|
|
||||||
out = p.communicate()[0]
|
|
||||||
self.assertEqual(out,
|
self.assertEqual(out,
|
||||||
b'stdin: ascii:strict\n'
|
'stdin: strict\n'
|
||||||
b'stdout: ascii:strict\n'
|
'stdout: strict\n'
|
||||||
b'stderr: ascii:backslashreplace\n')
|
'stderr: backslashreplace\n')
|
||||||
|
|
||||||
# force the encoding
|
# force the encoding
|
||||||
env['PYTHONIOENCODING'] = 'iso8859-1'
|
out = self.c_locale_get_error_handler(encoding='iso8859-1')
|
||||||
p = subprocess.Popen([sys.executable, "-c", code],
|
|
||||||
stdout=subprocess.PIPE, env=env)
|
|
||||||
out = p.communicate()[0]
|
|
||||||
self.assertEqual(out,
|
self.assertEqual(out,
|
||||||
b'stdin: iso8859-1:surrogateescape\n'
|
'stdin: surrogateescape\n'
|
||||||
b'stdout: iso8859-1:surrogateescape\n'
|
'stdout: surrogateescape\n'
|
||||||
b'stderr: iso8859-1:backslashreplace\n')
|
'stderr: backslashreplace\n')
|
||||||
|
|
||||||
def test_implementation(self):
|
def test_implementation(self):
|
||||||
# This test applies to all implementations equally.
|
# This test applies to all implementations equally.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user