diff options
Diffstat (limited to 'Lib/test/test__locale.py')
-rw-r--r-- | Lib/test/test__locale.py | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py index 3fadb57..4231f37 100644 --- a/Lib/test/test__locale.py +++ b/Lib/test/test__locale.py @@ -1,23 +1,25 @@ -from test.support import run_unittest from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, localeconv, Error) try: from _locale import (RADIXCHAR, THOUSEP, nl_langinfo) except ImportError: nl_langinfo = None -import unittest +import codecs +import locale import sys +import unittest from platform import uname +from test.support import run_unittest -if uname()[0] == "Darwin": - maj, min, mic = [int(part) for part in uname()[2].split(".")] +if uname().system == "Darwin": + maj, min, mic = [int(part) for part in uname().release.split(".")] if (maj, min, mic) < (8, 0, 0): raise unittest.SkipTest("locale support broken for OS X < 10.4") candidate_locales = ['es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT', 'et_EE', 'es_PY', 'no_NO', 'nl_NL', 'lv_LV', 'el_GR', 'be_BY', 'fr_BE', 'ro_RO', 'ru_UA', 'ru_RU', 'es_VE', 'ca_ES', 'se_NO', 'es_EC', 'id_ID', - 'ka_GE', 'es_CL', 'hu_HU', 'wa_BE', 'lt_LT', 'sl_SI', 'hr_HR', 'es_AR', + 'ka_GE', 'es_CL', 'wa_BE', 'hu_HU', 'lt_LT', 'sl_SI', 'hr_HR', 'es_AR', 'es_ES', 'oc_FR', 'gl_ES', 'bg_BG', 'is_IS', 'mk_MK', 'de_AT', 'pt_BR', 'da_DK', 'nn_NO', 'cs_CZ', 'de_LU', 'es_BO', 'sq_AL', 'sk_SK', 'fr_CH', 'de_DE', 'sr_YU', 'br_FR', 'nl_BE', 'sv_FI', 'pl_PL', 'fr_CA', 'fo_FO', @@ -25,6 +27,31 @@ candidate_locales = ['es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT', 'eu_ES', 'vi_VN', 'af_ZA', 'nb_NO', 'en_DK', 'tg_TJ', 'en_US', 'es_ES.ISO8859-1', 'fr_FR.ISO8859-15', 'ru_RU.KOI8-R', 'ko_KR.eucKR'] +# Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to +# workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses +# the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is +# decoded as U+30000020 (an invalid character) by mbstowcs(). +if sys.platform == 'sunos5': + old_locale = locale.setlocale(locale.LC_ALL) + try: + locales = [] + for loc in candidate_locales: + try: + locale.setlocale(locale.LC_ALL, loc) + except Error: + continue + encoding = locale.getpreferredencoding(False) + try: + localeconv() + except Exception as err: + print("WARNING: Skip locale %s (encoding %s): [%s] %s" + % (loc, encoding, type(err), err)) + else: + locales.append(loc) + candidate_locales = locales + finally: + locale.setlocale(locale.LC_ALL, old_locale) + # Workaround for MSVC6(debug) crash bug if "MSC v.1200" in sys.version: def accept(loc): @@ -86,9 +113,10 @@ class _LocaleTests(unittest.TestCase): setlocale(LC_CTYPE, loc) except Error: continue + formatting = localeconv() for lc in ("decimal_point", "thousands_sep"): - self.numeric_tester('localeconv', localeconv()[lc], lc, loc) + self.numeric_tester('localeconv', formatting[lc], lc, loc) @unittest.skipUnless(nl_langinfo, "nl_langinfo is not available") def test_lc_numeric_basic(self): |