summaryrefslogtreecommitdiffstats
path: root/Lib/test/test__locale.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2024-11-21 11:16:08 (GMT)
committerGitHub <noreply@github.com>2024-11-21 11:16:08 (GMT)
commit4803cd0244847f286641c85591fda08b513cea52 (patch)
treee6c1a444deff5366ba31b7ca6d321401bc245032 /Lib/test/test__locale.py
parenteaf217108226633c03cc5c4c90f0b6e4587c8803 (diff)
downloadcpython-4803cd0244847f286641c85591fda08b513cea52.zip
cpython-4803cd0244847f286641c85591fda08b513cea52.tar.gz
cpython-4803cd0244847f286641c85591fda08b513cea52.tar.bz2
gh-126727: Fix locale.nl_langinfo(locale.ERA) (GH-126730)
It now returns multiple era description segments separated by semicolons. Previously it only returned the first segment on platforms with Glibc.
Diffstat (limited to 'Lib/test/test__locale.py')
-rw-r--r--Lib/test/test__locale.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/Lib/test/test__locale.py b/Lib/test/test__locale.py
index 7e6e296..2c75103 100644
--- a/Lib/test/test__locale.py
+++ b/Lib/test/test__locale.py
@@ -90,6 +90,14 @@ known_alt_digits = {
'bn_IN': (100, {0: '\u09e6', 10: '\u09e7\u09e6', 99: '\u09ef\u09ef'}),
}
+known_era = {
+ 'C': (0, ''),
+ 'en_US': (0, ''),
+ 'ja_JP': (11, '+:1:2019/05/01:2019/12/31:令和:%EC元年'),
+ 'zh_TW': (3, '+:1:1912/01/01:1912/12/31:民國:%EC元年'),
+ 'th_TW': (1, '+:1:-543/01/01:+*:พ.ศ.:%EC %Ey'),
+}
+
if sys.platform == 'win32':
# ps_AF doesn't work on Windows: see bpo-38324 (msg361830)
del known_numerics['ps_AF']
@@ -230,6 +238,43 @@ class _LocaleTests(unittest.TestCase):
if not tested:
self.skipTest('no suitable locales')
+ @unittest.skipUnless(nl_langinfo, "nl_langinfo is not available")
+ @unittest.skipUnless(hasattr(locale, 'ERA'), "requires locale.ERA")
+ @unittest.skipIf(
+ support.is_emscripten or support.is_wasi,
+ "musl libc issue on Emscripten, bpo-46390"
+ )
+ def test_era_nl_langinfo(self):
+ # Test nl_langinfo(ERA)
+ tested = False
+ for loc in candidate_locales:
+ with self.subTest(locale=loc):
+ try:
+ setlocale(LC_TIME, loc)
+ except Error:
+ self.skipTest(f'no locale {loc!r}')
+ continue
+
+ with self.subTest(locale=loc):
+ era = nl_langinfo(locale.ERA)
+ self.assertIsInstance(era, str)
+ if era:
+ self.assertEqual(era.count(':'), (era.count(';') + 1) * 5, era)
+
+ loc1 = loc.split('.', 1)[0]
+ if loc1 in known_era:
+ count, sample = known_era[loc1]
+ if count:
+ if not era:
+ self.skipTest(f'ERA is not set for locale {loc!r} on this platform')
+ self.assertGreaterEqual(era.count(';') + 1, count)
+ self.assertIn(sample, era)
+ else:
+ self.assertEqual(era, '')
+ tested = True
+ if not tested:
+ self.skipTest('no suitable locales')
+
def test_float_parsing(self):
# Bug #1391872: Test whether float parsing is okay on European
# locales.