Commit 7847cd6b authored by Benjamin Peterson's avatar Benjamin Peterson

fix test__locale on windows #5643

parent b9ce9b51
from test.support import verbose, run_unittest from test.support import verbose, run_unittest
import _locale from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, localeconv, Error)
from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, nl_langinfo, try:
localeconv, Error) from _locale import (RADIXCHAR, THOUSEP, nl_langinfo)
except ImportError:
nl_langinfo = None
import unittest import unittest
import sys
from platform import uname from platform import uname
if uname()[0] == "Darwin": if uname()[0] == "Darwin":
...@@ -21,15 +25,18 @@ candidate_locales = ['es_UY', 'fr_FR', 'fi_FI', 'es_CO', 'pt_PT', 'it_IT', ...@@ -21,15 +25,18 @@ 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', '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'] 'es_ES.ISO8859-1', 'fr_FR.ISO8859-15', 'ru_RU.KOI8-R', 'ko_KR.eucKR']
# Workaround for MSVC6(debug) crash bug
if "MSC v.1200" in sys.version:
def accept(loc):
a = loc.split(".")
return not(len(a) == 2 and len(a[-1]) >= 9)
candidate_locales = [loc for loc in candidate_locales if accept(loc)]
# List known locale values to test against when available. # List known locale values to test against when available.
# Dict formatted as ``<locale> : (<decimal_point>, <thousands_sep>)``. If a # Dict formatted as ``<locale> : (<decimal_point>, <thousands_sep>)``. If a
# value is not known, use '' . # value is not known, use '' .
known_numerics = {'fr_FR' : (',', ''), 'en_US':('.', ',')} known_numerics = {'fr_FR' : (',', ''), 'en_US':('.', ',')}
def needs_radix_and_thousands(func):
return unittest.skipUnless(hasattr(_locale, "RADIXCHAR"),
"needs RADIXCHAR and THOUSEP")(func)
class _LocaleTests(unittest.TestCase): class _LocaleTests(unittest.TestCase):
def setUp(self): def setUp(self):
...@@ -58,7 +65,7 @@ class _LocaleTests(unittest.TestCase): ...@@ -58,7 +65,7 @@ class _LocaleTests(unittest.TestCase):
calc_type, data_type, set_locale, calc_type, data_type, set_locale,
used_locale)) used_locale))
@needs_radix_and_thousands @unittest.skipUnless(nl_langinfo, "nl_langinfo is not available")
def test_lc_numeric_nl_langinfo(self): def test_lc_numeric_nl_langinfo(self):
# Test nl_langinfo against known values # Test nl_langinfo against known values
for loc in candidate_locales: for loc in candidate_locales:
...@@ -67,11 +74,10 @@ class _LocaleTests(unittest.TestCase): ...@@ -67,11 +74,10 @@ class _LocaleTests(unittest.TestCase):
setlocale(LC_CTYPE, loc) setlocale(LC_CTYPE, loc)
except Error: except Error:
continue continue
for li, lc in ((_locale.RADIXCHAR, "decimal_point"), for li, lc in ((RADIXCHAR, "decimal_point"),
(_locale.THOUSEP, "thousands_sep")): (THOUSEP, "thousands_sep")):
self.numeric_tester('nl_langinfo', nl_langinfo(li), lc, loc) self.numeric_tester('nl_langinfo', nl_langinfo(li), lc, loc)
@needs_radix_and_thousands
def test_lc_numeric_localeconv(self): def test_lc_numeric_localeconv(self):
# Test localeconv against known values # Test localeconv against known values
for loc in candidate_locales: for loc in candidate_locales:
...@@ -80,11 +86,11 @@ class _LocaleTests(unittest.TestCase): ...@@ -80,11 +86,11 @@ class _LocaleTests(unittest.TestCase):
setlocale(LC_CTYPE, loc) setlocale(LC_CTYPE, loc)
except Error: except Error:
continue continue
for li, lc in ((_locale.RADIXCHAR, "decimal_point"), for lc in ("decimal_point",
(_locale.THOUSEP, "thousands_sep")): "thousands_sep"):
self.numeric_tester('localeconv', localeconv()[lc], lc, loc) self.numeric_tester('localeconv', localeconv()[lc], lc, loc)
@needs_radix_and_thousands @unittest.skipUnless(nl_langinfo, "nl_langinfo is not available")
def test_lc_numeric_basic(self): def test_lc_numeric_basic(self):
# Test nl_langinfo against localeconv # Test nl_langinfo against localeconv
for loc in candidate_locales: for loc in candidate_locales:
...@@ -93,8 +99,8 @@ class _LocaleTests(unittest.TestCase): ...@@ -93,8 +99,8 @@ class _LocaleTests(unittest.TestCase):
setlocale(LC_CTYPE, loc) setlocale(LC_CTYPE, loc)
except Error: except Error:
continue continue
for li, lc in ((_locale.RADIXCHAR, "decimal_point"), for li, lc in ((RADIXCHAR, "decimal_point"),
(_locale.THOUSEP, "thousands_sep")): (THOUSEP, "thousands_sep")):
nl_radixchar = nl_langinfo(li) nl_radixchar = nl_langinfo(li)
li_radixchar = localeconv()[lc] li_radixchar = localeconv()[lc]
try: try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment