Fred Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 1 | import calendar |
| 2 | import unittest |
| 3 | |
| 4 | from test_support import run_unittest |
| 5 | |
| 6 | |
| 7 | class 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 Montanaro | 693c6c4 | 2002-03-15 03:57:04 +0000 | [diff] [blame] | 29 | 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 Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 33 | |
Tim Peters | 0c2c8e7 | 2002-03-23 03:26:53 +0000 | [diff] [blame] | 34 | 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 Drake | d077ca1 | 2001-12-12 05:38:08 +0000 | [diff] [blame] | 57 | def test_main(): |
| 58 | run_unittest(CalendarTestCase) |
| 59 | |
| 60 | if __name__ == "__main__": |
| 61 | test_main() |