diff options
author | R. David Murray <rdmurray@bitdance.com> | 2010-12-31 19:31:48 +0000 |
---|---|---|
committer | R. David Murray <rdmurray@bitdance.com> | 2010-12-31 19:31:48 +0000 |
commit | c45d7996dbeb49e3fc07a0ab47380b7ec6f834a1 (patch) | |
tree | c16ad75e2922e97cb779a5eba3e2255574f421e6 | |
parent | 5dd32a2df296f77f5ce008bb055e66c7b245fb61 (diff) | |
download | cpython-git-c45d7996dbeb49e3fc07a0ab47380b7ec6f834a1.tar.gz |
Merged revisions 83089,87590 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k
........
r83089 | brett.cannon | 2010-07-23 09:54:14 -0400 (Fri, 23 Jul 2010) | 4 lines
Test calendar.monthrange.
Closes issue 9342. Thanks John Chandler for the patch.
........
r87590 | r.david.murray | 2010-12-31 14:21:14 -0500 (Fri, 31 Dec 2010) | 4 lines
#9361: add some tests for calendar.leapdays
Patch by John Chandler.
........
-rw-r--r-- | Lib/test/test_calendar.py | 52 | ||||
-rw-r--r-- | Misc/ACKS | 1 |
2 files changed, 52 insertions, 1 deletions
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index f20cc03929..2a56268810 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -394,12 +394,62 @@ class SundayTestCase(MonthCalendarTestCase): self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1)) +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) + +class LeapdaysTestCase(unittest.TestCase): + def test_no_range(self): + # test when no range i.e. two identical years as args + self.assertEqual(calendar.leapdays(2010,2010), 0) + + def test_no_leapdays(self): + # test when no leap years in range + self.assertEqual(calendar.leapdays(2010,2011), 0) + + def test_no_leapdays_upper_boundary(self): + # test no leap years in range, when upper boundary is a leap year + self.assertEqual(calendar.leapdays(2010,2012), 0) + + def test_one_leapday_lower_boundary(self): + # test when one leap year in range, lower boundary is leap year + self.assertEqual(calendar.leapdays(2012,2013), 1) + + def test_several_leapyears_in_range(self): + self.assertEqual(calendar.leapdays(1997,2020), 5) + + def test_main(): test_support.run_unittest( OutputTestCase, CalendarTestCase, MondayTestCase, - SundayTestCase + SundayTestCase, + MonthRangeTestCase, + LeapdaysTestCase, ) @@ -129,6 +129,7 @@ Charles Cazabon Per Cederqvist Octavian Cerna Pascal Chambon +John Chandler Hye-Shik Chang Jeffrey Chang Mitch Chapman |