Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 20 additions & 11 deletions 31 Lib/test/test_utf8_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,33 @@ def test_locale_getpreferredencoding(self):

@unittest.skipIf(MS_WINDOWS, 'test specific to Unix')
def test_cmd_line(self):
arg = 'h\xe9\u20ac'.encode('utf-8')
arg_utf8 = arg.decode('utf-8')
arg_ascii = arg.decode('ascii', 'surrogateescape')
code = 'import locale, sys; print("%s:%s" % (locale.getpreferredencoding(), ascii(sys.argv[1:])))'

def check(utf8_opt, expected, **kw):
out = self.get_output('-X', utf8_opt, '-c', code, arg, **kw)
args = out.partition(':')[2].rstrip()
self.assertEqual(args, ascii(expected), out)

check('utf8', [arg_utf8])
if sys.platform == 'darwin' or support.is_android:
c_arg = arg_utf8
elif sys.platform.startswith("aix"):
c_arg = arg.decode('iso-8859-1')
else:
c_arg = arg_ascii
check('utf8=0', [c_arg], LC_ALL='C')
# UTF-8 Mode must use the UTF-8 encoding for any locale
arg = 'h\xe9\u20ac\U0010ffff'.encode('utf-8')
check('utf8', [arg.decode('utf-8')])
check('utf8', [arg.decode('utf-8')], LC_ALL='C')

# Non-ASCII byte string. Don't test Euro sign (U+20AC): Roman8 doesn't
# support it, and HP-UX uses Roman8 encoding for its C locale. The
# test just requires a single non-ASCII character to validate the code.
arg = b'h\xa7\xe9'

# Get the locale encoding when the UTF-8 mode is disabled
out = self.get_output('-X', 'utf8=0', '-c',
'import locale; print(locale.getpreferredencoding())',
LC_ALL='C')
encoding = out.rstrip()

# Check that the command line is decoded from the locale encoding
with self.subTest(encoding=encoding):
check('utf8=0', [arg.decode(encoding, 'surrogateescape')],
LC_ALL='C')

def test_optim_level(self):
# CPython: check that Py_Main() doesn't increment Py_OptimizeFlag
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.