Skip to content

Commit 2b6f1f9

Browse files
committed
Expand the try clause to calls to LocaleTextCalendar.formatmonthname().
This method temporarily changes the current locale to the given locale, so `_locale.setlocale()` may raise `local.Error`.
1 parent 40e0da3 commit 2b6f1f9

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Lib/test/test_calendar.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -644,14 +644,14 @@ def test_locale_calendar_formatmonthname(self):
644644
try:
645645
# formatmonthname uses the same month names regardless of the width argument.
646646
cal = calendar.LocaleTextCalendar(locale='en_US')
647+
# For too short widths, a full name (with year) is used.
648+
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=False), "June")
649+
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=True), "June 2022")
650+
# For long widths, a centered name is used.
651+
self.assertEqual(cal.formatmonthname(2022, 6, 10, withyear=False), " June ")
652+
self.assertEqual(cal.formatmonthname(2022, 6, 15, withyear=True), " June 2022 ")
647653
except locale.Error:
648654
raise unittest.SkipTest('cannot set the en_US locale')
649-
# For too short widths, a full name (with year) is used.
650-
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=False), "June")
651-
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=True), "June 2022")
652-
# For long widths, a centered name is used.
653-
self.assertEqual(cal.formatmonthname(2022, 6, 10, withyear=False), " June ")
654-
self.assertEqual(cal.formatmonthname(2022, 6, 15, withyear=True), " June 2022 ")
655655

656656
def test_locale_html_calendar_custom_css_class_month_name(self):
657657
try:

0 commit comments

Comments
 (0)