blob: 2059eaf3558d555cda4ae83e473c337848851103 [file] [log] [blame]
Fred Draked077ca12001-12-12 05:38:08 +00001import calendar
2import unittest
3
4from test_support import run_unittest
5
6
7class CalendarTestCase(unittest.TestCase):
8 def test_isleap(self):
9 # Make sure that the return is right for a few years, and
10 # ensure that the return values are 1 or 0, not just true or
11 # false (see SF bug #485794). Specific additional tests may
12 # be appropriate; this tests a single "cycle".
13 self.assertEqual(calendar.isleap(2000), 1)
14 self.assertEqual(calendar.isleap(2001), 0)
15 self.assertEqual(calendar.isleap(2002), 0)
16 self.assertEqual(calendar.isleap(2003), 0)
17
18 def test_setfirstweekday(self):
19 self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
20 self.assertRaises(ValueError, calendar.setfirstweekday, -1)
21 self.assertRaises(ValueError, calendar.setfirstweekday, 200)
22 orig = calendar.firstweekday()
23 calendar.setfirstweekday(calendar.SUNDAY)
24 self.assertEqual(calendar.firstweekday(), calendar.SUNDAY)
25 calendar.setfirstweekday(calendar.MONDAY)
26 self.assertEqual(calendar.firstweekday(), calendar.MONDAY)
27 calendar.setfirstweekday(orig)
28
Skip Montanaro693c6c42002-03-15 03:57:04 +000029 def test_enumerateweekdays(self):
30 self.assertRaises(IndexError, calendar.day_abbr.__getitem__, -10)
31 self.assertRaises(IndexError, calendar.day_name.__getitem__, 10)
32 self.assertEqual(len([d for d in calendar.day_abbr]), 7)
Fred Draked077ca12001-12-12 05:38:08 +000033
Tim Peters0c2c8e72002-03-23 03:26:53 +000034 def test_days(self):
35 for attr in "day_name", "day_abbr":
36 value = getattr(calendar, attr)
37 self.assertEqual(len(value), 7)
38 self.assertEqual(len(value[:]), 7)
39 # ensure they're all unique
40 d = {}
41 for v in value:
42 d[v] = 1
43 self.assertEqual(len(d), 7)
44
45 def test_months(self):
46 for attr in "month_name", "month_abbr":
47 value = getattr(calendar, attr)
48 self.assertEqual(len(value), 13)
49 self.assertEqual(len(value[:]), 13)
50 self.assertEqual(value[0], "")
51 # ensure they're all unique
52 d = {}
53 for v in value:
54 d[v] = 1
55 self.assertEqual(len(d), 13)
56
Fred Draked077ca12001-12-12 05:38:08 +000057def test_main():
58 run_unittest(CalendarTestCase)
59
60if __name__ == "__main__":
61 test_main()