forked from Rust-related/RustPython
Update test_calendar from CPython 3.11
This commit is contained in:
57
Lib/test/test_calendar.py
vendored
57
Lib/test/test_calendar.py
vendored
@@ -564,6 +564,43 @@ class CalendarTestCase(unittest.TestCase):
|
||||
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))
|
||||
@@ -595,6 +632,14 @@ class CalendarTestCase(unittest.TestCase):
|
||||
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):
|
||||
@@ -837,7 +882,8 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
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:
|
||||
@@ -912,11 +958,10 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
|
||||
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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user