Skip to content

Commit c796689

Browse files
committed
provide a few locales to test
1 parent bb9a8b1 commit c796689

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

Lib/test/test_calendar.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -696,28 +696,24 @@ def test_locale_calendar_formatweekday(self):
696696
except locale.Error:
697697
raise unittest.SkipTest('cannot set the en_US locale')
698698

699-
def test_locale_calendar_shorter_day_names(self):
700-
locale_tested = False
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
718-
719-
if not locale_tested:
720-
raise unittest.SkipTest('cannot set the locale to a language with short weekday names')
699+
# These locales have weekday names all shorter than English's longest 'Wednesday'
700+
# They should not be abbreviated unnecessarily
701+
@support.run_with_locale("LC_ALL",
702+
'Chinese', 'zh_CN.UTF-8',
703+
'French', 'fr_FR.UTF-8',
704+
'Norwegian', 'nb_NO.UTF-8',
705+
'Malay', 'ms_MY.UTF8'
706+
)
707+
def test_locale_calendar_weekday_names(self):
708+
max_length = max(map(len, (datetime.date(2001, 1, i+1).strftime('%A') for i in range(7))))
709+
710+
get_weekday_names = lambda width: calendar.TextCalendar().formatweekheader(width).split()
711+
712+
# Full weekday name, not an abbreviation, should be used if the width is sufficient
713+
self.assertEqual(get_weekday_names(max_length), get_weekday_names(max_length + 10))
714+
715+
# Any width shorter than the longest necessary should produce abbreviations
716+
self.assertNotEqual(get_weekday_names(max_length), get_weekday_names(max_length - 1))
721717

722718
def test_locale_calendar_formatmonthname(self):
723719
try:

0 commit comments

Comments
 (0)