|
1 | 1 | import datetime |
| 2 | +import locale |
2 | 3 | import sys |
3 | 4 | import time |
4 | 5 | import unittest |
@@ -252,6 +253,26 @@ class DateTimeTest(unittest.TestCase): |
252 | 253 | datetime_module = datetime |
253 | 254 | theclass = datetime.datetime |
254 | 255 |
|
| 256 | + @support.run_with_locale("LC_TIME", "fr_FR.UTF-8", "fr_FR.utf8", |
| 257 | + "de_DE.UTF-8", "de_DE.utf8", "en_US.UTF-8", |
| 258 | + "en_US.utf8", "en_US") |
| 259 | + @hypothesis.settings(max_examples=25) |
| 260 | + @hypothesis.given(day=st.dates(), abbreviated=st.booleans()) |
| 261 | + @hypothesis.example(day=datetime.date.min, abbreviated=False) |
| 262 | + @hypothesis.example(day=datetime.date(2000, 2, 29), abbreviated=True) |
| 263 | + @hypothesis.example(day=datetime.date(2024, 8, 31), abbreviated=False) |
| 264 | + def test_locale_name_cache(self, day: datetime.date, abbreviated: bool) -> None: |
| 265 | + selected_locale = locale.setlocale(locale.LC_TIME) |
| 266 | + names = "%b|%a" if abbreviated else "%B|%A" |
| 267 | + fmt = "%Y|%d|" + names |
| 268 | + for locale_name in ("C", selected_locale, "C"): |
| 269 | + with support.run_with_locale("LC_TIME", locale_name): |
| 270 | + # Only obtain the localized names from libc. Construct years |
| 271 | + # ourselves so that this tests the full supported year range. |
| 272 | + value = f"{day.year:04}|{day.day}|{day.strftime(names)}" |
| 273 | + actual = self.theclass.strptime(value, fmt) |
| 274 | + self.assertEqual(actual.isoformat(), f"{day.isoformat()}T00:00:00") |
| 275 | + |
255 | 276 | # Known failure: duplicate regex group names leak re.PatternError instead |
256 | 277 | # of rejecting contradictory fields with the documented ValueError. |
257 | 278 | @unittest.expectedFailure |
|
0 commit comments