Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update test_calendar from CPython 3.11
  • Loading branch information
carlosmiei committed Mar 8, 2023
commit 7710ed00d3822abbf352fba0e3a25f6ef7a95e30
57 changes: 51 additions & 6 deletions Lib/test/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,43 @@ def test_locale_calendars(self):
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
self.assertEqual(old_october, new_october)

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))
Expand Down Expand Up @@ -595,6 +632,14 @@ def test_itermonthdays2(self):
self.assertEqual(days[0][1], firstweekday)
self.assertEqual(days[-1][1], (firstweekday - 1) % 7)

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):
Expand Down Expand Up @@ -837,7 +882,8 @@ def test_option_locale(self):
self.assertFailure('-L')
self.assertFailure('--locale')
self.assertFailure('-L', 'en')
lang, enc = locale.getdefaultlocale()

lang, enc = locale.getlocale()
lang = lang or 'C'
enc = enc or 'UTF-8'
try:
Expand Down Expand Up @@ -912,11 +958,10 @@ def test_html_output_year_css(self):

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)


Expand Down