diff options
author | Ronald Oussoren <ronaldoussoren@mac.com> | 2019-08-29 04:33:52 (GMT) |
---|---|---|
committer | Ned Deily <nad@python.org> | 2019-08-29 04:33:52 (GMT) |
commit | b0caf329815120acf50287e29858093d328b0e3c (patch) | |
tree | f7b3cce5c1d273c173872a45347208b39f21f0b3 /Lib/test | |
parent | fa220ec7633e9674baccc28dde987f29d7f65141 (diff) | |
download | cpython-b0caf329815120acf50287e29858093d328b0e3c.zip cpython-b0caf329815120acf50287e29858093d328b0e3c.tar.gz cpython-b0caf329815120acf50287e29858093d328b0e3c.tar.bz2 |
bpo-18378: Recognize "UTF-8" as a valid name in locale._parse_localename (GH-14736)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_locale.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/Lib/test/test_locale.py b/Lib/test/test_locale.py index 792a15c..c5d8e26 100644 --- a/Lib/test/test_locale.py +++ b/Lib/test/test_locale.py @@ -493,6 +493,42 @@ class NormalizeTest(unittest.TestCase): class TestMiscellaneous(unittest.TestCase): + def test_defaults_UTF8(self): + # Issue #18378: on (at least) macOS setting LC_CTYPE to "UTF-8" is + # valid. Futhermore LC_CTYPE=UTF is used by the UTF-8 locale coercing + # during interpreter startup (on macOS). + import _locale + import os + + self.assertEqual(locale._parse_localename('UTF-8'), (None, 'UTF-8')) + + if hasattr(_locale, '_getdefaultlocale'): + orig_getlocale = _locale._getdefaultlocale + del _locale._getdefaultlocale + else: + orig_getlocale = None + + orig_env = {} + try: + for key in ('LC_ALL', 'LC_CTYPE', 'LANG', 'LANGUAGE'): + if key in os.environ: + orig_env[key] = os.environ[key] + del os.environ[key] + + os.environ['LC_CTYPE'] = 'UTF-8' + + self.assertEqual(locale.getdefaultlocale(), (None, 'UTF-8')) + + finally: + for k in orig_env: + os.environ[k] = orig_env[k] + + if 'LC_CTYPE' not in orig_env: + del os.environ['LC_CTYPE'] + + if orig_getlocale is not None: + _locale._getdefaultlocale = orig_getlocale + def test_getpreferredencoding(self): # Invoke getpreferredencoding to make sure it does not cause exceptions. enc = locale.getpreferredencoding() |