Update calendar.py from CPython 3.11 by carlosmiei · Pull Request #4669 · RustPython/RustPython
def test_locale_calendar_formatweekday(self): try: # formatweekday uses different day names based on the available width. cal = calendar.LocaleTextCalendar(locale='en_US') # For short widths, a centered, abbreviated name is used. self.assertEqual(cal.formatweekday(0, 5), " Mon ") # For really short widths, even the abbreviated name is truncated. self.assertEqual(cal.formatweekday(0, 2), "Mo") # For long widths, the full day name is used. self.assertEqual(cal.formatweekday(0, 10), " Monday ") except locale.Error: raise unittest.SkipTest('cannot set the en_US locale')
def test_locale_html_calendar_custom_css_class_month_name(self): try: cal = calendar.LocaleHTMLCalendar(locale='') local_month = cal.formatmonthname(2010, 10, 10) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIn('class="month"', local_month) cal.cssclass_month_head = "text-center month" local_month = cal.formatmonthname(2010, 10, 10) self.assertIn('class="text-center month"', local_month)
def test_locale_html_calendar_custom_css_class_weekday(self): try: cal = calendar.LocaleHTMLCalendar(locale='') local_weekday = cal.formatweekday(6) except locale.Error: # cannot set the system default locale -- skip rest of test raise unittest.SkipTest('cannot set the system default locale') self.assertIn('class="sun"', local_weekday) cal.cssclasses_weekday_head = ["mon2", "tue2", "wed2", "thu2", "fri2", "sat2", "sun2"] local_weekday = cal.formatweekday(6) self.assertIn('class="sun2"', local_weekday)
def test_itermonthdays3(self): # ensure itermonthdays3 doesn't overflow after datetime.MAXYEAR list(calendar.Calendar().itermonthdays3(datetime.MAXYEAR, 12))
def test_iterweekdays(self): week0 = list(range(7)) for firstweekday in range(7): cal = calendar.Calendar(firstweekday) week = list(cal.iterweekdays()) expected = week0[firstweekday:] + week0[:firstweekday] self.assertEqual(week, expected)
class MonthCalendarTestCase(unittest.TestCase): def setUp(self):
lang, enc = locale.getlocale() lang = lang or 'C' enc = enc or 'UTF-8' try:
class MiscTestCase(unittest.TestCase): def test__all__(self): not_exported = {'mdays', 'January', 'February', 'EPOCH', 'MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY', 'different_locale', 'c', 'prweek', 'week', 'format', 'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth'} not_exported = { 'mdays', 'January', 'February', 'EPOCH', 'different_locale', 'c', 'prweek', 'week', 'format', 'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth'} support.check__all__(self, calendar, not_exported=not_exported)