Commit 2c33ae04 authored by Victor Stinner's avatar Victor Stinner

test_undecodable_code(): set locale to C

The test is still failing on "x86 FreeBSD 7.2 3.x" and "sparc solaris10 gcc
3.x" buildbots. It looks like the locale encoding is able to decode b'\xff'. I
suppose that it is an encoding like 'iso-8859-1'.

Use C locale to set, I hope, the locale encoding to 'ascii'. Display also the
encoding so if the test fails, at least I will learn the locale encoding
choosen for the C locale.
parent 62aa0223
...@@ -495,24 +495,21 @@ class SysModuleTest(unittest.TestCase): ...@@ -495,24 +495,21 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys.intern, S("abc")) self.assertRaises(TypeError, sys.intern, S("abc"))
def test_main_invalid_unicode(self): def test_undecodable_code(self):
import locale
non_decodable = b"\xff" non_decodable = b"\xff"
encoding = locale.getpreferredencoding() env = os.environ.copy()
try: env['LANG'] = 'C'
non_decodable.decode(encoding) code = b'import locale; '
except UnicodeDecodeError: code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
pass p = subprocess.Popen(
else: [sys.executable, "-c", code],
self.skipTest('%r is decodable with encoding %s' stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
% (non_decodable, encoding)) env=env)
code = b'print(ascii("' + non_decodable + b'"))'
p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE)
stdout, stderr = p.communicate() stdout, stderr = p.communicate()
self.assertEqual(p.returncode, 1)
pattern = b"Unable to decode the command from the command line:" pattern = b"Unable to decode the command from the command line:"
if not stderr.startswith(pattern): if not stdout.startswith(pattern):
raise AssertionError("%a doesn't start with %a" % (stderr, pattern)) raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
self.assertEqual(p.returncode, 1)
def test_sys_flags(self): def test_sys_flags(self):
self.assertTrue(sys.flags) self.assertTrue(sys.flags)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment