@@ -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