99import sys
1010import unittest
1111from platform import uname
12- from test .support import run_unittest
1312
1413if uname ().system == "Darwin" :
1514 maj , min , mic = [int (part ) for part in uname ().release .split ("." )]
2423 'da_DK' , 'nn_NO' , 'cs_CZ' , 'de_LU' , 'es_BO' , 'sq_AL' , 'sk_SK' , 'fr_CH' ,
2524 'de_DE' , 'sr_YU' , 'br_FR' , 'nl_BE' , 'sv_FI' , 'pl_PL' , 'fr_CA' , 'fo_FO' ,
2625 'bs_BA' , 'fr_LU' , 'kl_GL' , 'fa_IR' , 'de_BE' , 'sv_SE' , 'it_CH' , 'uk_UA' ,
27- 'eu_ES' , 'vi_VN' , 'af_ZA' , 'nb_NO' , 'en_DK' , 'tg_TJ' , 'en_US' ,
26+ 'eu_ES' , 'vi_VN' , 'af_ZA' , 'nb_NO' , 'en_DK' , 'tg_TJ' , 'ps_AF' , ' en_US' ,
2827 'es_ES.ISO8859-1' , 'fr_FR.ISO8859-15' , 'ru_RU.KOI8-R' , 'ko_KR.eucKR' ]
2928
30- # Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
31- # workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
32- # the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is
33- # decoded as U+30000020 (an invalid character) by mbstowcs().
34- if sys .platform == 'sunos5' :
35- old_locale = locale .setlocale (locale .LC_ALL )
36- try :
37- locales = []
38- for loc in candidate_locales :
39- try :
40- locale .setlocale (locale .LC_ALL , loc )
41- except Error :
42- continue
43- encoding = locale .getpreferredencoding (False )
44- try :
45- localeconv ()
46- except Exception as err :
47- print ("WARNING: Skip locale %s (encoding %s): [%s] %s"
48- % (loc , encoding , type (err ), err ))
49- else :
50- locales .append (loc )
51- candidate_locales = locales
52- finally :
53- locale .setlocale (locale .LC_ALL , old_locale )
54-
55- # Workaround for MSVC6(debug) crash bug
56- if "MSC v.1200" in sys .version :
57- def accept (loc ):
58- a = loc .split ("." )
59- return not (len (a ) == 2 and len (a [- 1 ]) >= 9 )
60- candidate_locales = [loc for loc in candidate_locales if accept (loc )]
29+ def setUpModule ():
30+ global candidate_locales
31+ # Issue #13441: Skip some locales (e.g. cs_CZ and hu_HU) on Solaris to
32+ # workaround a mbstowcs() bug. For example, on Solaris, the hu_HU locale uses
33+ # the locale encoding ISO-8859-2, the thousauds separator is b'\xA0' and it is
34+ # decoded as U+30000020 (an invalid character) by mbstowcs().
35+ if sys .platform == 'sunos5' :
36+ old_locale = locale .setlocale (locale .LC_ALL )
37+ try :
38+ locales = []
39+ for loc in candidate_locales :
40+ try :
41+ locale .setlocale (locale .LC_ALL , loc )
42+ except Error :
43+ continue
44+ encoding = locale .getpreferredencoding (False )
45+ try :
46+ localeconv ()
47+ except Exception as err :
48+ print ("WARNING: Skip locale %s (encoding %s): [%s] %s"
49+ % (loc , encoding , type (err ), err ))
50+ else :
51+ locales .append (loc )
52+ candidate_locales = locales
53+ finally :
54+ locale .setlocale (locale .LC_ALL , old_locale )
55+
56+ # Workaround for MSVC6(debug) crash bug
57+ if "MSC v.1200" in sys .version :
58+ def accept (loc ):
59+ a = loc .split ("." )
60+ return not (len (a ) == 2 and len (a [- 1 ]) >= 9 )
61+ candidate_locales = [loc for loc in candidate_locales if accept (loc )]
6162
6263# List known locale values to test against when available.
6364# Dict formatted as ``<locale> : (<decimal_point>, <thousands_sep>)``. If a
6465# value is not known, use '' .
65- known_numerics = {'fr_FR' : (',' , '' ), 'en_US' :('.' , ',' )}
66+ known_numerics = {
67+ 'en_US' : ('.' , ',' ),
68+ 'fr_FR' : (',' , ' ' ),
69+ 'de_DE' : (',' , '.' ),
70+ 'ps_AF' : ('\u066b ' , '\u066c ' ),
71+ }
6672
6773class _LocaleTests (unittest .TestCase ):
6874
@@ -91,10 +97,12 @@ def numeric_tester(self, calc_type, calc_value, data_type, used_locale):
9197 calc_value , known_value ,
9298 calc_type , data_type , set_locale ,
9399 used_locale ))
100+ return True
94101
95102 @unittest .skipUnless (nl_langinfo , "nl_langinfo is not available" )
96103 def test_lc_numeric_nl_langinfo (self ):
97104 # Test nl_langinfo against known values
105+ tested = False
98106 for loc in candidate_locales :
99107 try :
100108 setlocale (LC_NUMERIC , loc )
@@ -103,10 +111,14 @@ def test_lc_numeric_nl_langinfo(self):
103111 continue
104112 for li , lc in ((RADIXCHAR , "decimal_point" ),
105113 (THOUSEP , "thousands_sep" )):
106- self .numeric_tester ('nl_langinfo' , nl_langinfo (li ), lc , loc )
114+ if self .numeric_tester ('nl_langinfo' , nl_langinfo (li ), lc , loc ):
115+ tested = True
116+ if not tested :
117+ self .skipTest ('no suitable locales' )
107118
108119 def test_lc_numeric_localeconv (self ):
109120 # Test localeconv against known values
121+ tested = False
110122 for loc in candidate_locales :
111123 try :
112124 setlocale (LC_NUMERIC , loc )
@@ -116,11 +128,15 @@ def test_lc_numeric_localeconv(self):
116128 formatting = localeconv ()
117129 for lc in ("decimal_point" ,
118130 "thousands_sep" ):
119- self .numeric_tester ('localeconv' , formatting [lc ], lc , loc )
131+ if self .numeric_tester ('localeconv' , formatting [lc ], lc , loc ):
132+ tested = True
133+ if not tested :
134+ self .skipTest ('no suitable locales' )
120135
121136 @unittest .skipUnless (nl_langinfo , "nl_langinfo is not available" )
122137 def test_lc_numeric_basic (self ):
123138 # Test nl_langinfo against localeconv
139+ tested = False
124140 for loc in candidate_locales :
125141 try :
126142 setlocale (LC_NUMERIC , loc )
@@ -140,10 +156,14 @@ def test_lc_numeric_basic(self):
140156 "(set to %s, using %s)" % (
141157 nl_radixchar , li_radixchar ,
142158 loc , set_locale ))
159+ tested = True
160+ if not tested :
161+ self .skipTest ('no suitable locales' )
143162
144163 def test_float_parsing (self ):
145164 # Bug #1391872: Test whether float parsing is okay on European
146165 # locales.
166+ tested = False
147167 for loc in candidate_locales :
148168 try :
149169 setlocale (LC_NUMERIC , loc )
@@ -162,9 +182,10 @@ def test_float_parsing(self):
162182 if localeconv ()['decimal_point' ] != '.' :
163183 self .assertRaises (ValueError , float ,
164184 localeconv ()['decimal_point' ].join (['1' , '23' ]))
185+ tested = True
186+ if not tested :
187+ self .skipTest ('no suitable locales' )
165188
166- def test_main ():
167- run_unittest (_LocaleTests )
168189
169190if __name__ == '__main__' :
170- test_main ()
191+ unittest . main ()
0 commit comments