mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Workaround issue #8611 in test_undecodable_code() of test_sys
Write test.support.workaroundIssue8611() function so it will be easier to remove this workaround from all tests.
This commit is contained in:
parent
1b6372a1d1
commit
c44abb127b
3 changed files with 36 additions and 31 deletions
|
@ -1277,3 +1277,11 @@ def strip_python_stderr(stderr):
|
||||||
"""
|
"""
|
||||||
stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
|
stderr = re.sub(br"\[\d+ refs\]\r?\n?$", b"", stderr).strip()
|
||||||
return stderr
|
return stderr
|
||||||
|
|
||||||
|
def workaroundIssue8611():
|
||||||
|
try:
|
||||||
|
sys.executable.encode('ascii')
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
raise unittest.SkipTest(
|
||||||
|
"Issue #8611: Python doesn't support ascii locale encoding "
|
||||||
|
"with an non-ascii path")
|
||||||
|
|
|
@ -1175,15 +1175,12 @@ class FSEncodingTests(unittest.TestCase):
|
||||||
self.assertEqual(decoded, repr(unicodefn))
|
self.assertEqual(decoded, repr(unicodefn))
|
||||||
|
|
||||||
check('utf-8', b'\xc3\xa9\x80', '\xe9\udc80')
|
check('utf-8', b'\xc3\xa9\x80', '\xe9\udc80')
|
||||||
try:
|
|
||||||
sys.executable.encode("ascii")
|
# Raise SkipTest() if sys.executable is not encodable to ascii
|
||||||
except UnicodeEncodeError:
|
support.workaroundIssue8611()
|
||||||
# Python doesn't start with ASCII locale if its path is not ASCII,
|
|
||||||
# see issue #8611
|
check('ascii', b'abc\xff', 'abc\udcff')
|
||||||
pass
|
check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
|
||||||
else:
|
|
||||||
check('ascii', b'abc\xff', 'abc\udcff')
|
|
||||||
check('iso-8859-15', b'\xef\xa4', '\xef\u20ac')
|
|
||||||
|
|
||||||
|
|
||||||
def test_main():
|
def test_main():
|
||||||
|
|
|
@ -496,11 +496,16 @@ class SysModuleTest(unittest.TestCase):
|
||||||
self.assertRaises(TypeError, sys.intern, S("abc"))
|
self.assertRaises(TypeError, sys.intern, S("abc"))
|
||||||
|
|
||||||
def test_undecodable_code(self):
|
def test_undecodable_code(self):
|
||||||
non_decodable = b"\xff"
|
# Raise SkipTest() if sys.executable is not encodable to ascii
|
||||||
|
test.support.workaroundIssue8611()
|
||||||
|
|
||||||
|
undecodable = b"\xff"
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['LANG'] = 'C'
|
env['LANG'] = 'C'
|
||||||
code = b'import locale; '
|
code = (
|
||||||
code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
|
b'import locale; '
|
||||||
|
b'print(ascii("' + undecodable + b'"), '
|
||||||
|
b'locale.getpreferredencoding())')
|
||||||
p = subprocess.Popen(
|
p = subprocess.Popen(
|
||||||
[sys.executable, "-c", code],
|
[sys.executable, "-c", code],
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||||
|
@ -587,28 +592,23 @@ class SysModuleTest(unittest.TestCase):
|
||||||
env=env)
|
env=env)
|
||||||
return output.rstrip().decode('ascii')
|
return output.rstrip().decode('ascii')
|
||||||
|
|
||||||
|
# Raise SkipTest() if sys.executable is not encodable to ascii
|
||||||
|
test.support.workaroundIssue8611()
|
||||||
|
|
||||||
|
# Even in C locale
|
||||||
|
env = os.environ.copy()
|
||||||
|
env['LANG'] = 'C'
|
||||||
try:
|
try:
|
||||||
sys.executable.encode('ascii')
|
del env['PYTHONFSENCODING']
|
||||||
except UnicodeEncodeError:
|
except KeyError:
|
||||||
# Python doesn't start with ASCII locale if its path is not ASCII,
|
|
||||||
# see issue #8611
|
|
||||||
pass
|
pass
|
||||||
else:
|
self.check_fsencoding(get_fsencoding(env), 'ascii')
|
||||||
# Even in C locale
|
|
||||||
|
# Filesystem encoding is hardcoded on Windows and Mac OS X
|
||||||
|
for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'):
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env['LANG'] = 'C'
|
env['PYTHONFSENCODING'] = encoding
|
||||||
try:
|
self.check_fsencoding(get_fsencoding(env), encoding)
|
||||||
del env['PYTHONFSENCODING']
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
self.check_fsencoding(get_fsencoding(env), 'ascii')
|
|
||||||
|
|
||||||
# Filesystem encoding is hardcoded on Windows and Mac OS X
|
|
||||||
for encoding in ('ascii', 'cp850', 'iso8859-1', 'utf-8'):
|
|
||||||
env = os.environ.copy()
|
|
||||||
env['PYTHONFSENCODING'] = encoding
|
|
||||||
self.check_fsencoding(get_fsencoding(env), encoding)
|
|
||||||
|
|
||||||
|
|
||||||
def test_setfilesystemencoding(self):
|
def test_setfilesystemencoding(self):
|
||||||
old = sys.getfilesystemencoding()
|
old = sys.getfilesystemencoding()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue