Merged revisions 83089,87590 via svnmerge from
authorR. David Murray <rdmurray@bitdance.com>
Fri, 31 Dec 2010 19:29:08 +0000 (19:29 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Fri, 31 Dec 2010 19:29:08 +0000 (19:29 +0000)
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
Misc/ACKS

index a4839a682b75f6d66a7d825aa28c6204510679f8..f2969e285d31bd056880e5db5bb718b5e974b457 100644 (file)
@@ -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,
     )
 
 
index 03f73a29d27c5fc28ed9ec11c25234170996943d..02a0724fde677db911809b5dd1d2cbd7fee5de13 100644 (file)
--- 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