summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-08-20 16:38:14 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2010-08-20 16:38:14 (GMT)
commit1b6372a1d1e0b68e6b29e02fd1af8c721aeaa52b (patch)
treed9297f9c6d893b417de5f45caf0837877782e300
parente6376f8849175789c371f292f896ecdccb88b5b1 (diff)
downloadcpython-1b6372a1d1e0b68e6b29e02fd1af8c721aeaa52b.zip
cpython-1b6372a1d1e0b68e6b29e02fd1af8c721aeaa52b.tar.gz
cpython-1b6372a1d1e0b68e6b29e02fd1af8c721aeaa52b.tar.bz2
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.
-rw-r--r--Lib/test/test_sys.py27
1 files changed, 12 insertions, 15 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py
index 448fd3f..e09601f 100644
--- a/Lib/test/test_sys.py
+++ b/Lib/test/test_sys.py
@@ -495,24 +495,21 @@ class SysModuleTest(unittest.TestCase):
self.assertRaises(TypeError, sys.intern, S("abc"))
- def test_main_invalid_unicode(self):
- import locale
+ def test_undecodable_code(self):
non_decodable = b"\xff"
- encoding = locale.getpreferredencoding()
- try:
- non_decodable.decode(encoding)
- except UnicodeDecodeError:
- pass
- else:
- self.skipTest('%r is decodable with encoding %s'
- % (non_decodable, encoding))
- code = b'print(ascii("' + non_decodable + b'"))'
- p = subprocess.Popen([sys.executable, "-c", code], stderr=subprocess.PIPE)
+ env = os.environ.copy()
+ env['LANG'] = 'C'
+ code = b'import locale; '
+ code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())'
+ p = subprocess.Popen(
+ [sys.executable, "-c", code],
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ env=env)
stdout, stderr = p.communicate()
- self.assertEqual(p.returncode, 1)
pattern = b"Unable to decode the command from the command line:"
- if not stderr.startswith(pattern):
- raise AssertionError("%a doesn't start with %a" % (stderr, pattern))
+ if not stdout.startswith(pattern):
+ raise AssertionError("%a doesn't start with %a" % (stdout, pattern))
+ self.assertEqual(p.returncode, 1)
def test_sys_flags(self):
self.assertTrue(sys.flags)