Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1b6372a

Browse files
author
Victor Stinner
committed
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.
1 parent e6376f8 commit 1b6372a

1 file changed

Lines changed: 12 additions & 15 deletions

File tree

Lib/test/test_sys.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -495,24 +495,21 @@ def __hash__(self):
495495

496496
self.assertRaises(TypeError, sys.intern, S("abc"))
497497

498-
def test_main_invalid_unicode(self):
499-
import locale
498+
def test_undecodable_code(self):
500499
non_decodable = b"\xff"
501-
encoding = locale.getpreferredencoding()
502-
try:
503-
non_decodable.decode(encoding)
504-
except UnicodeDecodeError:
505-
pass
506-
else:
507-
self.skipTest('%r is decodable with encoding %s'
508-
% (non_decodable, encoding))
509-
code = b'print(ascii("' + non_decodable + b'"))'
510-
p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE)
500+
env = os.environ.copy()
501+
env['LANG'] = 'C'
502+
code = b'import locale; '
503+
code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
504+
p = subprocess.Popen(
505+
[sys.executable, "-c", code],
506+
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
507+
env=env)
511508
stdout, stderr = p.communicate()
512-
self.assertEqual(p.returncode, 1)
513509
pattern = b"Unable to decode the command from the command line:"
514-
if not stderr.startswith(pattern):
515-
raise AssertionError("%a doesn't start with %a" % (stderr, pattern))
510+
if not stdout.startswith(pattern):
511+
raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
512+
self.assertEqual(p.returncode, 1)
516513

517514
def test_sys_flags(self):
518515
self.assertTrue(sys.flags)

0 commit comments

Comments
 (0)