|
1 |
| -from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, localeconv, Error) |
| 1 | +from _locale import (setlocale, LC_ALL, LC_CTYPE, LC_NUMERIC, LC_TIME, localeconv, Error) |
2 | 2 | try:
|
3 | 3 | from _locale import (RADIXCHAR, THOUSEP, nl_langinfo)
|
4 | 4 | except ImportError:
|
@@ -74,6 +74,17 @@ def accept(loc):
|
74 | 74 | 'ps_AF': ('\u066b', '\u066c'),
|
75 | 75 | }
|
76 | 76 |
|
| 77 | +known_alt_digits = { |
| 78 | + 'C': (0, {}), |
| 79 | + 'en_US': (0, {}), |
| 80 | + 'fa_IR': (100, {0: '\u06f0\u06f0', 10: '\u06f1\u06f0', 99: '\u06f9\u06f9'}), |
| 81 | + 'ja_JP': (100, {0: '\u3007', 10: '\u5341', 99: '\u4e5d\u5341\u4e5d'}), |
| 82 | + 'lzh_TW': (32, {0: '\u3007', 10: '\u5341', 31: '\u5345\u4e00'}), |
| 83 | + 'my_MM': (100, {0: '\u1040\u1040', 10: '\u1041\u1040', 99: '\u1049\u1049'}), |
| 84 | + 'or_IN': (100, {0: '\u0b66', 10: '\u0b67\u0b66', 99: '\u0b6f\u0b6f'}), |
| 85 | + 'shn_MM': (100, {0: '\u1090\u1090', 10: '\u1091\u1090', 99: '\u1099\u1099'}), |
| 86 | +} |
| 87 | + |
77 | 88 | if sys.platform == 'win32':
|
78 | 89 | # ps_AF doesn't work on Windows: see bpo-38324 (msg361830)
|
79 | 90 | del known_numerics['ps_AF']
|
@@ -179,6 +190,30 @@ def test_lc_numeric_basic(self):
|
179 | 190 | if not tested:
|
180 | 191 | self.skipTest('no suitable locales')
|
181 | 192 |
|
| 193 | + @unittest.skipUnless(nl_langinfo, "nl_langinfo is not available") |
| 194 | + @unittest.skipUnless(hasattr(locale, 'ALT_DIGITS'), "requires locale.ALT_DIGITS") |
| 195 | + @unittest.skipIf( |
| 196 | + support.is_emscripten or support.is_wasi, |
| 197 | + "musl libc issue on Emscripten, bpo-46390" |
| 198 | + ) |
| 199 | + def test_alt_digits_nl_langinfo(self): |
| 200 | + # Test nl_langinfo(ALT_DIGITS) |
| 201 | + tested = False |
| 202 | + for loc, (count, samples) in known_alt_digits.items(): |
| 203 | + try: |
| 204 | + setlocale(LC_TIME, loc) |
| 205 | + except Error: |
| 206 | + continue |
| 207 | + with self.subTest(locale=loc): |
| 208 | + alt_digits = nl_langinfo(locale.ALT_DIGITS) |
| 209 | + self.assertIsInstance(alt_digits, tuple) |
| 210 | + self.assertEqual(len(alt_digits), count) |
| 211 | + for i in samples: |
| 212 | + self.assertEqual(alt_digits[i], samples[i]) |
| 213 | + tested = True |
| 214 | + if not tested: |
| 215 | + self.skipTest('no suitable locales') |
| 216 | + |
182 | 217 | def test_float_parsing(self):
|
183 | 218 | # Bug #1391872: Test whether float parsing is okay on European
|
184 | 219 | # locales.
|
|
0 commit comments