Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 488b485

Browse files
committed
Merged revisions 83089,87590 via svnmerge from
svn+ssh://[email protected]/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. ........
1 parent f9f2e02 commit 488b485

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

Lib/test/test_calendar.py

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,62 @@ def test_december(self):
396396
self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1))
397397

398398

399+
class MonthRangeTestCase(unittest.TestCase):
400+
def test_january(self):
401+
# Tests valid lower boundary case.
402+
self.assertEqual(calendar.monthrange(2004,1), (3,31))
403+
404+
def test_february_leap(self):
405+
# Tests February during leap year.
406+
self.assertEqual(calendar.monthrange(2004,2), (6,29))
407+
408+
def test_february_nonleap(self):
409+
# Tests February in non-leap year.
410+
self.assertEqual(calendar.monthrange(2010,2), (0,28))
411+
412+
def test_december(self):
413+
# Tests valid upper boundary case.
414+
self.assertEqual(calendar.monthrange(2004,12), (2,31))
415+
416+
def test_zeroth_month(self):
417+
# Tests low invalid boundary case.
418+
with self.assertRaises(calendar.IllegalMonthError):
419+
calendar.monthrange(2004, 0)
420+
421+
def test_thirteenth_month(self):
422+
# Tests high invalid boundary case.
423+
with self.assertRaises(calendar.IllegalMonthError):
424+
calendar.monthrange(2004, 13)
425+
426+
class LeapdaysTestCase(unittest.TestCase):
427+
def test_no_range(self):
428+
# test when no range i.e. two identical years as args
429+
self.assertEqual(calendar.leapdays(2010,2010), 0)
430+
431+
def test_no_leapdays(self):
432+
# test when no leap years in range
433+
self.assertEqual(calendar.leapdays(2010,2011), 0)
434+
435+
def test_no_leapdays_upper_boundary(self):
436+
# test no leap years in range, when upper boundary is a leap year
437+
self.assertEqual(calendar.leapdays(2010,2012), 0)
438+
439+
def test_one_leapday_lower_boundary(self):
440+
# test when one leap year in range, lower boundary is leap year
441+
self.assertEqual(calendar.leapdays(2012,2013), 1)
442+
443+
def test_several_leapyears_in_range(self):
444+
self.assertEqual(calendar.leapdays(1997,2020), 5)
445+
446+
399447
def test_main():
400448
support.run_unittest(
401449
OutputTestCase,
402450
CalendarTestCase,
403451
MondayTestCase,
404-
SundayTestCase
452+
SundayTestCase,
453+
MonthRangeTestCase,
454+
LeapdaysTestCase,
405455
)
406456

407457

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Donn Cave
126126
Per Cederqvist
127127
Octavian Cerna
128128
Pascal Chambon
129+
John Chandler
129130
Hye-Shik Chang
130131
Jeffrey Chang
131132
Mitch Chapman

0 commit comments

Comments
 (0)