diff options
author | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-20 16:52:14 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@haypocalc.com> | 2010-08-20 16:52:14 (GMT) |
commit | c44abb127b3567d7f371d84e767641649fa2137c (patch) | |
tree | 9f47bc03b5dbf0151996e470421bdbb03b3d4390 /Lib/test/test_sys.py | |
parent | 1b6372a1d1e0b68e6b29e02fd1af8c721aeaa52b (diff) | |
download | cpython-c44abb127b3567d7f371d84e767641649fa2137c.zip cpython-c44abb127b3567d7f371d84e767641649fa2137c.tar.gz cpython-c44abb127b3567d7f371d84e767641649fa2137c.tar.bz2 |
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.
Diffstat (limited to 'Lib/test/test_sys.py')
-rw-r--r-- | Lib/test/test_sys.py | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index e09601f..294814d 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -496,11 +496,16 @@ class SysModuleTest(unittest.TestCase): self.assertRaises(TypeError, sys.intern, S("abc")) 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['LANG'] = 'C' - code = b'import locale; ' - code += b'print(ascii("' + non_decodable + b'"), locale.getpreferredencoding())' + code = ( + b'import locale; ' + b'print(ascii("' + undecodable + b'"), ' + b'locale.getpreferredencoding())') p = subprocess.Popen( [sys.executable, "-c", code], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, @@ -587,28 +592,23 @@ class SysModuleTest(unittest.TestCase): env=env) 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: - sys.executable.encode('ascii') - except UnicodeEncodeError: - # Python doesn't start with ASCII locale if its path is not ASCII, - # see issue #8611 + del env['PYTHONFSENCODING'] + except KeyError: pass - else: - # Even in C locale - env = os.environ.copy() - env['LANG'] = 'C' - try: - 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) + 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): old = sys.getfilesystemencoding() |