From 488b485e2babe8a8c9b596813779c0310e52781f Mon Sep 17 00:00:00 2001 From: "R. David Murray" Date: Fri, 31 Dec 2010 19:29:08 +0000 Subject: 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. ........ --- Lib/test/test_calendar.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++- Misc/ACKS | 1 + 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index a4839a6..f2969e2 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -396,12 +396,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(): support.run_unittest( OutputTestCase, CalendarTestCase, MondayTestCase, - SundayTestCase + SundayTestCase, + MonthRangeTestCase, + LeapdaysTestCase, ) diff --git a/Misc/ACKS b/Misc/ACKS index 03f73a2..02a0724 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -126,6 +126,7 @@ Donn Cave Per Cederqvist Octavian Cerna Pascal Chambon +John Chandler Hye-Shik Chang Jeffrey Chang Mitch Chapman -- cgit v0.12