@@ -564,6 +564,43 @@ def test_locale_calendars(self):
564
564
new_october = calendar .TextCalendar ().formatmonthname (2010 , 10 , 10 )
565
565
self .assertEqual (old_october , new_october )
566
566
567
+ def test_locale_calendar_formatweekday (self ):
568
+ try :
569
+ # formatweekday uses different day names based on the available width.
570
+ cal = calendar .LocaleTextCalendar (locale = 'en_US' )
571
+ # For short widths, a centered, abbreviated name is used.
572
+ self .assertEqual (cal .formatweekday (0 , 5 ), " Mon " )
573
+ # For really short widths, even the abbreviated name is truncated.
574
+ self .assertEqual (cal .formatweekday (0 , 2 ), "Mo" )
575
+ # For long widths, the full day name is used.
576
+ self .assertEqual (cal .formatweekday (0 , 10 ), " Monday " )
577
+ except locale .Error :
578
+ raise unittest .SkipTest ('cannot set the en_US locale' )
579
+
580
+ def test_locale_html_calendar_custom_css_class_month_name (self ):
581
+ try :
582
+ cal = calendar .LocaleHTMLCalendar (locale = '' )
583
+ local_month = cal .formatmonthname (2010 , 10 , 10 )
584
+ except locale .Error :
585
+ # cannot set the system default locale -- skip rest of test
586
+ raise unittest .SkipTest ('cannot set the system default locale' )
587
+ self .assertIn ('class="month"' , local_month )
588
+ cal .cssclass_month_head = "text-center month"
589
+ local_month = cal .formatmonthname (2010 , 10 , 10 )
590
+ self .assertIn ('class="text-center month"' , local_month )
591
+
592
+ def test_locale_html_calendar_custom_css_class_weekday (self ):
593
+ try :
594
+ cal = calendar .LocaleHTMLCalendar (locale = '' )
595
+ local_weekday = cal .formatweekday (6 )
596
+ except locale .Error :
597
+ # cannot set the system default locale -- skip rest of test
598
+ raise unittest .SkipTest ('cannot set the system default locale' )
599
+ self .assertIn ('class="sun"' , local_weekday )
600
+ cal .cssclasses_weekday_head = ["mon2" , "tue2" , "wed2" , "thu2" , "fri2" , "sat2" , "sun2" ]
601
+ local_weekday = cal .formatweekday (6 )
602
+ self .assertIn ('class="sun2"' , local_weekday )
603
+
567
604
def test_itermonthdays3 (self ):
568
605
# ensure itermonthdays3 doesn't overflow after datetime.MAXYEAR
569
606
list (calendar .Calendar ().itermonthdays3 (datetime .MAXYEAR , 12 ))
@@ -595,6 +632,14 @@ def test_itermonthdays2(self):
595
632
self .assertEqual (days [0 ][1 ], firstweekday )
596
633
self .assertEqual (days [- 1 ][1 ], (firstweekday - 1 ) % 7 )
597
634
635
+ def test_iterweekdays (self ):
636
+ week0 = list (range (7 ))
637
+ for firstweekday in range (7 ):
638
+ cal = calendar .Calendar (firstweekday )
639
+ week = list (cal .iterweekdays ())
640
+ expected = week0 [firstweekday :] + week0 [:firstweekday ]
641
+ self .assertEqual (week , expected )
642
+
598
643
599
644
class MonthCalendarTestCase (unittest .TestCase ):
600
645
def setUp (self ):
@@ -837,7 +882,8 @@ def test_option_locale(self):
837
882
self .assertFailure ('-L' )
838
883
self .assertFailure ('--locale' )
839
884
self .assertFailure ('-L' , 'en' )
840
- lang , enc = locale .getdefaultlocale ()
885
+
886
+ lang , enc = locale .getlocale ()
841
887
lang = lang or 'C'
842
888
enc = enc or 'UTF-8'
843
889
try :
@@ -912,11 +958,10 @@ def test_html_output_year_css(self):
912
958
913
959
class MiscTestCase (unittest .TestCase ):
914
960
def test__all__ (self ):
915
- not_exported = {'mdays' , 'January' , 'February' , 'EPOCH' ,
916
- 'MONDAY' , 'TUESDAY' , 'WEDNESDAY' , 'THURSDAY' , 'FRIDAY' ,
917
- 'SATURDAY' , 'SUNDAY' , 'different_locale' , 'c' ,
918
- 'prweek' , 'week' , 'format' , 'formatstring' , 'main' ,
919
- 'monthlen' , 'prevmonth' , 'nextmonth' }
961
+ not_exported = {
962
+ 'mdays' , 'January' , 'February' , 'EPOCH' ,
963
+ 'different_locale' , 'c' , 'prweek' , 'week' , 'format' ,
964
+ 'formatstring' , 'main' , 'monthlen' , 'prevmonth' , 'nextmonth' }
920
965
support .check__all__ (self , calendar , not_exported = not_exported )
921
966
922
967
0 commit comments