Skip to content

Commit 62b065c

Browse files
committed
test all locales
1 parent 29a18cc commit 62b065c

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

Lib/test/test_calendar.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -698,20 +698,23 @@ def test_locale_calendar_formatweekday(self):
698698

699699
def test_locale_calendar_shorter_day_names(self):
700700
locale_tested = False
701-
for locale_name in [
702-
'french', 'fr_FR.UTF-8',
703-
'malay', 'ms_MY.UTF-8',
704-
'norwegian', 'nb_NO.UTF-8',
705-
'danish', 'da_DK.UTF-8'
706-
]:
707-
try:
708-
cal = calendar.LocaleTextCalendar(locale=locale_name)
709-
week_header_split = lambda width: cal.formatweekheader(width).split()
710-
self.assertEqual(week_header_split(8), week_header_split(9))
711-
locale_tested = True
712-
break
713-
except locale.Error:
714-
continue
701+
for locale_name in locale.locale_alias.keys():
702+
if len(locale_name) < 16: # avoiding a crashing bug on older versions of Python on Windows
703+
try:
704+
with calendar.different_locale(locale_name):
705+
max_length = max(map(len, (datetime.date(2001, 1, i+1).strftime('%A') for i in range(7))))
706+
707+
cal = calendar.TextCalendar()
708+
week_header_split = lambda width: cal.formatweekheader(width).split()
709+
710+
# Full weekday name should be used whenever the width is sufficient
711+
self.assertEqual(week_header_split(max_length), week_header_split(max_length + 10))
712+
# Any width shorter than the longest necessary should return abbreviations
713+
self.assertNotEqual(week_header_split(max_length), week_header_split(max_length - 1))
714+
715+
locale_tested = True
716+
except locale.Error:
717+
continue
715718

716719
if not locale_tested:
717720
raise unittest.SkipTest('cannot set the locale to a language with short weekday names')

0 commit comments

Comments
 (0)