summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_c_locale_coercion.py5
-rw-r--r--Lib/test/test_cmd_line.py2
-rw-r--r--Lib/test/test_utf8_mode.py30
3 files changed, 30 insertions, 7 deletions
diff --git a/Lib/test/test_c_locale_coercion.py b/Lib/test/test_c_locale_coercion.py
index c0845d75a2..37dd834781 100644
--- a/Lib/test/test_c_locale_coercion.py
+++ b/Lib/test/test_c_locale_coercion.py
@@ -65,7 +65,7 @@ def _set_locale_in_subprocess(locale_name):
# If there's no valid CODESET, we expect coercion to be skipped
cmd_fmt += "; import sys; sys.exit(not locale.nl_langinfo(locale.CODESET))"
cmd = cmd_fmt.format(locale_name)
- result, py_cmd = run_python_until_end("-c", cmd, __isolated=True)
+ result, py_cmd = run_python_until_end("-c", cmd, PYTHONCOERCECLOCALE='')
return result.rc == 0
@@ -131,7 +131,6 @@ class EncodingDetails(_EncodingDetails):
"""
result, py_cmd = run_python_until_end(
"-X", "utf8=0", "-c", cls.CHILD_PROCESS_SCRIPT,
- __isolated=True,
**env_vars
)
if not result.rc == 0:
@@ -236,6 +235,7 @@ class LocaleConfigurationTests(_LocaleHandlingTestCase):
"LANG": "",
"LC_CTYPE": "",
"LC_ALL": "",
+ "PYTHONCOERCECLOCALE": "",
}
for env_var in ("LANG", "LC_CTYPE"):
for locale_to_set in AVAILABLE_TARGETS:
@@ -294,6 +294,7 @@ class LocaleCoercionTests(_LocaleHandlingTestCase):
"LANG": "",
"LC_CTYPE": "",
"LC_ALL": "",
+ "PYTHONCOERCECLOCALE": "",
}
base_var_dict.update(extra_vars)
for env_var in ("LANG", "LC_CTYPE"):
diff --git a/Lib/test/test_cmd_line.py b/Lib/test/test_cmd_line.py
index 2b14c301c7..54ea3773a0 100644
--- a/Lib/test/test_cmd_line.py
+++ b/Lib/test/test_cmd_line.py
@@ -551,7 +551,7 @@ class CmdLineTest(unittest.TestCase):
self.assertEqual(out, "True")
# Warnings
- code = ("import sys, warnings; "
+ code = ("import warnings; "
"print(' '.join('%s::%s' % (f[0], f[2].__name__) "
"for f in warnings.filters))")
if Py_DEBUG:
diff --git a/Lib/test/test_utf8_mode.py b/Lib/test/test_utf8_mode.py
index 275a6ea8ed..73d1bd424c 100644
--- a/Lib/test/test_utf8_mode.py
+++ b/Lib/test/test_utf8_mode.py
@@ -7,6 +7,7 @@ import os
import sys
import textwrap
import unittest
+from test import support
from test.support.script_helper import assert_python_ok, assert_python_failure
@@ -14,9 +15,11 @@ MS_WINDOWS = (sys.platform == 'win32')
class UTF8ModeTests(unittest.TestCase):
- # Override PYTHONUTF8 and PYTHONLEGACYWINDOWSFSENCODING environment
- # variables by default
- DEFAULT_ENV = {'PYTHONUTF8': '', 'PYTHONLEGACYWINDOWSFSENCODING': ''}
+ DEFAULT_ENV = {
+ 'PYTHONUTF8': '',
+ 'PYTHONLEGACYWINDOWSFSENCODING': '',
+ 'PYTHONCOERCECLOCALE': '0',
+ }
def posix_locale(self):
loc = locale.setlocale(locale.LC_CTYPE, None)
@@ -53,7 +56,7 @@ class UTF8ModeTests(unittest.TestCase):
self.assertEqual(out, '0')
if MS_WINDOWS:
- # PYTHONLEGACYWINDOWSFSENCODING disables the UTF-8
+ # PYTHONLEGACYWINDOWSFSENCODING disables the UTF-8 Mode
# and has the priority over -X utf8
out = self.get_output('-X', 'utf8', '-c', code,
PYTHONLEGACYWINDOWSFSENCODING='1')
@@ -201,6 +204,25 @@ class UTF8ModeTests(unittest.TestCase):
out = self.get_output('-X', 'utf8', '-c', code, LC_ALL='C')
self.assertEqual(out, 'UTF-8 UTF-8')
+ @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
+ else:
+ c_arg = arg_ascii
+ check('utf8=0', [c_arg], LC_ALL='C')
+
if __name__ == "__main__":
unittest.main()