Skip to content

Commit 69c8f4f

Browse files
committed
gh-69714: Add missing test cases for custom locale in calendar.Locale{Text|HTML}Calendar
There are 3 paths to use `locale` argument in `calendar.Locale{Text|HTML}Calendar.__init__(..., locale=None)`: (1) `locale=None` -- denotes the "default locale"[1] (2) `locale=""` -- denotes the native environment (3) `locale=other_valid_locale` -- denotes a custom locale So far case (2) is covered and case (1) is in 78935da (same branch). This commit adds a remaining case (3). [1] In the current implementation, this translates into the following approach: GET current locale IF current locale == "C" THEN SET current locale TO "" GET current locale ENDIF
1 parent 0dd6321 commit 69c8f4f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Lib/test/test_calendar.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,17 @@ def test_locale_calendars(self):
571571
self.assertEqual(len(local_weekday_abbr), 3)
572572
self.assertGreaterEqual(len(local_month), 10)
573573

574+
cal = calendar.LocaleTextCalendar(locale='C')
575+
local_weekday = cal.formatweekday(1, 10)
576+
local_weekday_abbr = cal.formatweekday(1, 3)
577+
local_month = cal.formatmonthname(2010, 10, 10)
578+
self.assertIsInstance(local_weekday, str)
579+
self.assertIsInstance(local_weekday_abbr, str)
580+
self.assertIsInstance(local_month, str)
581+
self.assertEqual(len(local_weekday), 10)
582+
self.assertEqual(len(local_weekday_abbr), 3)
583+
self.assertGreaterEqual(len(local_month), 10)
584+
574585
cal = calendar.LocaleHTMLCalendar(locale=None)
575586
local_weekday = cal.formatweekday(1)
576587
local_month = cal.formatmonthname(2010, 10)
@@ -583,6 +594,12 @@ def test_locale_calendars(self):
583594
self.assertIsInstance(local_weekday, str)
584595
self.assertIsInstance(local_month, str)
585596

597+
cal = calendar.LocaleHTMLCalendar(locale='C')
598+
local_weekday = cal.formatweekday(1)
599+
local_month = cal.formatmonthname(2010, 10)
600+
self.assertIsInstance(local_weekday, str)
601+
self.assertIsInstance(local_month, str)
602+
586603
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
587604
self.assertEqual(old_october, new_october)
588605

0 commit comments

Comments
 (0)