diff options
author | Brett Cannon <bcannon@gmail.com> | 2010-07-23 13:54:14 (GMT) |
---|---|---|
committer | Brett Cannon <bcannon@gmail.com> | 2010-07-23 13:54:14 (GMT) |
commit | cfae36fa8e550ecbe9b270da5ace9306d09245e4 (patch) | |
tree | d10d414c86626dece683982e94bd7df0d132e787 | |
parent | b6ee4f5bfcaad3c63055ec0e99c0382ff23548d8 (diff) | |
download | cpython-cfae36fa8e550ecbe9b270da5ace9306d09245e4.zip cpython-cfae36fa8e550ecbe9b270da5ace9306d09245e4.tar.gz cpython-cfae36fa8e550ecbe9b270da5ace9306d09245e4.tar.bz2 |
Test calendar.monthrange.
Closes issue 9342. Thanks John Chandler for the patch.
-rw-r--r-- | Lib/test/test_calendar.py | 29 | ||||
-rw-r--r-- | Misc/ACKS | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index b7ce475..b936acb 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -389,6 +389,34 @@ class TimegmTestCase(unittest.TestCase): tuple = time.gmtime(secs) self.assertEqual(secs, calendar.timegm(tuple)) +class MonthRangeTestCase(unittest.TestCase): + def test_january(self): + # Tests valid lower boundary case. + self.assertEqual(calendar.monthrange(2004,1), (3,31)) + + def test_february_leap(self): + # Tests February during leap year. + self.assertEqual(calendar.monthrange(2004,2), (6,29)) + + def test_february_nonleap(self): + # Tests February in non-leap year. + self.assertEqual(calendar.monthrange(2010,2), (0,28)) + + def test_december(self): + # Tests valid upper boundary case. + self.assertEqual(calendar.monthrange(2004,12), (2,31)) + + def test_zeroth_month(self): + # Tests low invalid boundary case. + with self.assertRaises(calendar.IllegalMonthError): + calendar.monthrange(2004, 0) + + def test_thirteenth_month(self): + # Tests high invalid boundary case. + with self.assertRaises(calendar.IllegalMonthError): + calendar.monthrange(2004, 13) + + def test_main(): support.run_unittest( OutputTestCase, @@ -396,6 +424,7 @@ def test_main(): MondayTestCase, SundayTestCase, TimegmTestCase, + MonthRangeTestCase, ) @@ -129,6 +129,7 @@ Charles Cazabon Per Cederqvist Octavian Cerna Pascal Chambon +John Chandler Hye-Shik Chang Jeffrey Chang Mitch Chapman |