mirror of
https://github.com/python/cpython.git
synced 2024-11-25 19:03:49 +08:00
e549ead826
svn+ssh://pythondev@svn.python.org/python/trunk ........ r70554 | benjamin.peterson | 2009-03-23 16:25:15 -0500 (Mon, 23 Mar 2009) | 1 line complain when there's no last exception ........ r70588 | benjamin.peterson | 2009-03-24 17:56:32 -0500 (Tue, 24 Mar 2009) | 1 line fix newline issue in test summary ........ r70589 | benjamin.peterson | 2009-03-24 18:07:07 -0500 (Tue, 24 Mar 2009) | 1 line another style nit ........ r70598 | benjamin.peterson | 2009-03-25 16:24:04 -0500 (Wed, 25 Mar 2009) | 1 line add shorthands for expected failures and unexpected success ........ r70605 | benjamin.peterson | 2009-03-26 11:32:23 -0500 (Thu, 26 Mar 2009) | 1 line remove uneeded function ........ r70611 | benjamin.peterson | 2009-03-26 13:35:37 -0500 (Thu, 26 Mar 2009) | 1 line add much better tests for python version information parsing ........ r70612 | benjamin.peterson | 2009-03-26 13:55:48 -0500 (Thu, 26 Mar 2009) | 1 line more and more implementations now support sys.subversion ........ r70613 | benjamin.peterson | 2009-03-26 13:58:30 -0500 (Thu, 26 Mar 2009) | 1 line roll old test in with new one ........ r70614 | benjamin.peterson | 2009-03-26 14:09:21 -0500 (Thu, 26 Mar 2009) | 1 line add support for PyPy ........ r70615 | benjamin.peterson | 2009-03-26 14:58:18 -0500 (Thu, 26 Mar 2009) | 5 lines add some useful utilities for skipping tests with unittest's new skipping ability most significantly apply a modified portion of the patch from #4242 with patches for skipping implementation details ........ r70616 | benjamin.peterson | 2009-03-26 15:05:50 -0500 (Thu, 26 Mar 2009) | 1 line rename TestCase.skip() to skipTest() because it causes annoying problems with trial #5571 ........ r70617 | benjamin.peterson | 2009-03-26 15:17:27 -0500 (Thu, 26 Mar 2009) | 1 line apply the second part of #4242's patch; classify all the implementation details in test_descr ........ r70618 | benjamin.peterson | 2009-03-26 15:48:25 -0500 (Thu, 26 Mar 2009) | 1 line remove test_support.TestSkipped and just use unittest.SkipTest ........ r70619 | benjamin.peterson | 2009-03-26 15:49:40 -0500 (Thu, 26 Mar 2009) | 1 line fix naming ........ r70620 | benjamin.peterson | 2009-03-26 16:10:30 -0500 (Thu, 26 Mar 2009) | 1 line fix incorrect auto-translation of TestSkipped -> unittest.SkipTest ........ r70621 | benjamin.peterson | 2009-03-26 16:11:16 -0500 (Thu, 26 Mar 2009) | 1 line must pass argument to get expected behavior ;) ........ r70623 | benjamin.peterson | 2009-03-26 16:30:10 -0500 (Thu, 26 Mar 2009) | 1 line add missing import ........ r70624 | benjamin.peterson | 2009-03-26 16:30:54 -0500 (Thu, 26 Mar 2009) | 1 line ** is required here ........ r70626 | benjamin.peterson | 2009-03-26 16:40:29 -0500 (Thu, 26 Mar 2009) | 1 line update email tests to use SkipTest ........ r70627 | benjamin.peterson | 2009-03-26 16:44:43 -0500 (Thu, 26 Mar 2009) | 1 line fix another name ........
129 lines
5.5 KiB
Python
129 lines
5.5 KiB
Python
from test.support import verbose, run_unittest
|
|
from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, RADIXCHAR, THOUSEP, nl_langinfo,
|
|
localeconv, Error)
|
|
import unittest
|
|
from platform import uname
|
|
|
|
if uname()[0] == "Darwin":
|
|
maj, min, mic = [int(part) for part in uname()[2].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',
|
|
'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',
|
|
'bs_BA', 'fr_LU', 'kl_GL', 'fa_IR', 'de_BE', 'sv_SE', 'it_CH', 'uk_UA',
|
|
'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']
|
|
|
|
# List known locale values to test against when available.
|
|
# Dict formatted as ``<locale> : (<decimal_point>, <thousands_sep>)``. If a
|
|
# value is not known, use '' .
|
|
known_numerics = {'fr_FR' : (',', ''), 'en_US':('.', ',')}
|
|
|
|
class _LocaleTests(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.oldlocale = setlocale(LC_ALL)
|
|
|
|
def tearDown(self):
|
|
setlocale(LC_ALL, self.oldlocale)
|
|
|
|
# Want to know what value was calculated, what it was compared against,
|
|
# what function was used for the calculation, what type of data was used,
|
|
# the locale that was supposedly set, and the actual locale that is set.
|
|
lc_numeric_err_msg = "%s != %s (%s for %s; set to %s, using %s)"
|
|
|
|
def numeric_tester(self, calc_type, calc_value, data_type, used_locale):
|
|
"""Compare calculation against known value, if available"""
|
|
try:
|
|
set_locale = setlocale(LC_NUMERIC)
|
|
except Error:
|
|
set_locale = "<not able to determine>"
|
|
known_value = known_numerics.get(used_locale,
|
|
('', ''))[data_type == 'thousands_sep']
|
|
if known_value and calc_value:
|
|
self.assertEquals(calc_value, known_value,
|
|
self.lc_numeric_err_msg % (
|
|
calc_value, known_value,
|
|
calc_type, data_type, set_locale,
|
|
used_locale))
|
|
|
|
def test_lc_numeric_nl_langinfo(self):
|
|
# Test nl_langinfo against known values
|
|
for loc in candidate_locales:
|
|
try:
|
|
setlocale(LC_NUMERIC, loc)
|
|
setlocale(LC_CTYPE, loc)
|
|
except Error:
|
|
continue
|
|
for li, lc in ((RADIXCHAR, "decimal_point"),
|
|
(THOUSEP, "thousands_sep")):
|
|
self.numeric_tester('nl_langinfo', nl_langinfo(li), lc, loc)
|
|
|
|
def test_lc_numeric_localeconv(self):
|
|
# Test localeconv against known values
|
|
for loc in candidate_locales:
|
|
try:
|
|
setlocale(LC_NUMERIC, loc)
|
|
setlocale(LC_CTYPE, loc)
|
|
except Error:
|
|
continue
|
|
for li, lc in ((RADIXCHAR, "decimal_point"),
|
|
(THOUSEP, "thousands_sep")):
|
|
self.numeric_tester('localeconv', localeconv()[lc], lc, loc)
|
|
|
|
def test_lc_numeric_basic(self):
|
|
# Test nl_langinfo against localeconv
|
|
for loc in candidate_locales:
|
|
try:
|
|
setlocale(LC_NUMERIC, loc)
|
|
setlocale(LC_CTYPE, loc)
|
|
except Error:
|
|
continue
|
|
for li, lc in ((RADIXCHAR, "decimal_point"),
|
|
(THOUSEP, "thousands_sep")):
|
|
nl_radixchar = nl_langinfo(li)
|
|
li_radixchar = localeconv()[lc]
|
|
try:
|
|
set_locale = setlocale(LC_NUMERIC)
|
|
except Error:
|
|
set_locale = "<not able to determine>"
|
|
self.assertEquals(nl_radixchar, li_radixchar,
|
|
"%s (nl_langinfo) != %s (localeconv) "
|
|
"(set to %s, using %s)" % (
|
|
nl_radixchar, li_radixchar,
|
|
loc, set_locale))
|
|
|
|
def test_float_parsing(self):
|
|
# Bug #1391872: Test whether float parsing is okay on European
|
|
# locales.
|
|
for loc in candidate_locales:
|
|
try:
|
|
setlocale(LC_NUMERIC, loc)
|
|
setlocale(LC_CTYPE, loc)
|
|
except Error:
|
|
continue
|
|
|
|
# Ignore buggy locale databases. (Mac OS 10.4 and some other BSDs)
|
|
if loc == 'eu_ES' and localeconv()['decimal_point'] == "' ":
|
|
continue
|
|
|
|
self.assertEquals(int(eval('3.14') * 100), 314,
|
|
"using eval('3.14') failed for %s" % loc)
|
|
self.assertEquals(int(float('3.14') * 100), 314,
|
|
"using float('3.14') failed for %s" % loc)
|
|
if localeconv()['decimal_point'] != '.':
|
|
self.assertRaises(ValueError, float,
|
|
localeconv()['decimal_point'].join(['1', '23']))
|
|
|
|
def test_main():
|
|
run_unittest(_LocaleTests)
|
|
|
|
if __name__ == '__main__':
|
|
test_main()
|