@@ -696,6 +696,52 @@ def test_locale_calendar_formatweekday(self):
696
696
except locale .Error :
697
697
raise unittest .SkipTest ('cannot set the en_US locale' )
698
698
699
+ # These locales have weekday names all shorter than English's longest
700
+ # 'Wednesday'. They should not be abbreviated unnecessarily
701
+ @support .run_with_locales ("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_short_weekday_names (self ):
708
+ names = (datetime .date (2001 , 1 , i + 1 ).strftime ('%A' ) for i in range (7 ))
709
+ max_length = max (map (len , names ))
710
+ if max_length >= 9 :
711
+ self .skipTest ('weekday names are too long' )
712
+
713
+ def get_weekday_names (width ):
714
+ return calendar .TextCalendar ().formatweekheader (width ).split ()
715
+
716
+ # Weekday names should not be abbreviated if the width is sufficient
717
+ self .assertEqual (
718
+ get_weekday_names (max_length ),
719
+ get_weekday_names (max_length + 10 )
720
+ )
721
+
722
+ # Any width shorter than necessary should produce abbreviations
723
+ self .assertNotEqual (
724
+ get_weekday_names (max_length ),
725
+ get_weekday_names (max_length - 1 )
726
+ )
727
+
728
+ # These locales have a weekday name longer than 'Wednesday'
729
+ # They should be properly abbreviated rather than truncated
730
+ @support .run_with_locales ("LC_ALL" ,
731
+ 'Portuguese' , 'pt_PT.UTF-8' ,
732
+ 'German' , 'de_DE.UTF-8' ,
733
+ 'Russian' , 'ru_RU.UTF-8' ,
734
+ )
735
+ def test_locale_calendar_long_weekday_names (self ):
736
+ names = (datetime .date (2001 , 1 , i + 1 ).strftime ('%A' ) for i in range (7 ))
737
+ max_length = max (map (len , names ))
738
+ if max_length <= 9 :
739
+ self .skipTest ('weekday names are too short' )
740
+
741
+ def get_weekday_names (width ):
742
+ return calendar .TextCalendar ().formatweekheader (width ).split ()
743
+ self .assertEqual (get_weekday_names (4 ), get_weekday_names (9 ))
744
+
699
745
def test_locale_calendar_formatmonthname (self ):
700
746
try :
701
747
# formatmonthname uses the same month names regardless of the width argument.
0 commit comments