]> granicus.if.org Git - python/commitdiff
Test calendar.monthrange.
authorBrett Cannon <bcannon@gmail.com>
Fri, 23 Jul 2010 13:54:14 +0000 (13:54 +0000)
committerBrett Cannon <bcannon@gmail.com>
Fri, 23 Jul 2010 13:54:14 +0000 (13:54 +0000)
Closes issue 9342. Thanks John Chandler for the patch.

Lib/test/test_calendar.py
Misc/ACKS

index b7ce4750e0ed2e536527fdf791dd4839f58bfaee..b936acb3e9499bcdf7a2dd24a82ac2f0f9f24d0b 100644 (file)
@@ -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,
     )
 
 
index 44b813634279084a6598a82c4647f02e2d553131..f890ee94cb070a824a31e4b8fbc6b5863591cc69 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -129,6 +129,7 @@ Charles Cazabon
 Per Cederqvist
 Octavian Cerna
 Pascal Chambon
+John Chandler
 Hye-Shik Chang
 Jeffrey Chang
 Mitch Chapman