summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorR. David Murray <rdmurray@bitdance.com>2010-12-31 19:29:08 (GMT)
committerR. David Murray <rdmurray@bitdance.com>2010-12-31 19:29:08 (GMT)
commit488b485e2babe8a8c9b596813779c0310e52781f (patch)
treebee3f4fa7b887f07a51ab0cd6f328c03e1b5b85d /Lib
parentf9f2e02de51321f06944164459830742c5eb1452 (diff)
downloadcpython-488b485e2babe8a8c9b596813779c0310e52781f.zip
cpython-488b485e2babe8a8c9b596813779c0310e52781f.tar.gz
cpython-488b485e2babe8a8c9b596813779c0310e52781f.tar.bz2
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. ........
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_calendar.py52
1 files changed, 51 insertions, 1 deletions
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,
)