2001-12-12 01:38:08 -04:00
|
|
|
import calendar
|
|
|
|
import unittest
|
|
|
|
|
2003-05-01 14:45:56 -03:00
|
|
|
from test import test_support
|
2001-12-12 01:38:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
class CalendarTestCase(unittest.TestCase):
|
|
|
|
def test_isleap(self):
|
|
|
|
# Make sure that the return is right for a few years, and
|
|
|
|
# ensure that the return values are 1 or 0, not just true or
|
|
|
|
# false (see SF bug #485794). Specific additional tests may
|
|
|
|
# be appropriate; this tests a single "cycle".
|
|
|
|
self.assertEqual(calendar.isleap(2000), 1)
|
|
|
|
self.assertEqual(calendar.isleap(2001), 0)
|
|
|
|
self.assertEqual(calendar.isleap(2002), 0)
|
|
|
|
self.assertEqual(calendar.isleap(2003), 0)
|
|
|
|
|
|
|
|
def test_setfirstweekday(self):
|
|
|
|
self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
|
|
|
|
self.assertRaises(ValueError, calendar.setfirstweekday, -1)
|
|
|
|
self.assertRaises(ValueError, calendar.setfirstweekday, 200)
|
|
|
|
orig = calendar.firstweekday()
|
|
|
|
calendar.setfirstweekday(calendar.SUNDAY)
|
|
|
|
self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
|
|
|
|
calendar.setfirstweekday(calendar.MONDAY)
|
|
|
|
self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
|
|
|
|
calendar.setfirstweekday(orig)
|
|
|
|
|
2002-03-14 23:57:04 -04:00
|
|
|
def test_enumerateweekdays(self):
|
|
|
|
self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10)
|
|
|
|
self.assertRaises(IndexError, calendar.day_name.__getitem__, 10)
|
|
|
|
self.assertEqual(len([d for d in calendar.day_abbr]), 7)
|
2001-12-12 01:38:08 -04:00
|
|
|
|
2002-03-22 23:26:53 -04:00
|
|
|
def test_days(self):
|
|
|
|
for attr in "day_name", "day_abbr":
|
|
|
|
value = getattr(calendar, attr)
|
|
|
|
self.assertEqual(len(value), 7)
|
|
|
|
self.assertEqual(len(value[:]), 7)
|
|
|
|
# ensure they're all unique
|
|
|
|
d = {}
|
|
|
|
for v in value:
|
|
|
|
d[v] = 1
|
|
|
|
self.assertEqual(len(d), 7)
|
|
|
|
|
|
|
|
def test_months(self):
|
|
|
|
for attr in "month_name", "month_abbr":
|
|
|
|
value = getattr(calendar, attr)
|
|
|
|
self.assertEqual(len(value), 13)
|
|
|
|
self.assertEqual(len(value[:]), 13)
|
|
|
|
self.assertEqual(value[0], "")
|
|
|
|
# ensure they're all unique
|
|
|
|
d = {}
|
|
|
|
for v in value:
|
|
|
|
d[v] = 1
|
|
|
|
self.assertEqual(len(d), 13)
|
|
|
|
|
2001-12-12 01:38:08 -04:00
|
|
|
def test_main():
|
2003-05-01 14:45:56 -03:00
|
|
|
test_support.run_unittest(CalendarTestCase)
|
2001-12-12 01:38:08 -04:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
test_main()
|