summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_calendar.py
diff options
context:
space:
mode:
authorAlexander Belopolsky <alexander.belopolsky@gmail.com>2016-09-28 00:27:55 (GMT)
committerAlexander Belopolsky <alexander.belopolsky@gmail.com>2016-09-28 00:27:55 (GMT)
commite3fd248c771e1a8bf337a4a307dacf1e85106611 (patch)
tree3991349a04581590bc8d6099520554cbaa02acb6 /Lib/test/test_calendar.py
parent6703e042fa0005dbf76578ddf24c7c170a715061 (diff)
parent957b75699fd1ed2eb18e8f7fa6fee1062fabad68 (diff)
downloadcpython-e3fd248c771e1a8bf337a4a307dacf1e85106611.zip
cpython-e3fd248c771e1a8bf337a4a307dacf1e85106611.tar.gz
cpython-e3fd248c771e1a8bf337a4a307dacf1e85106611.tar.bz2
Issue #28253: Fixed calendar functions for extreme months: 0001-01 and 9999-12.
Methods itermonthdays() and itermonthdays2() are reimplemented so that they don't call itermonthdates() which can cause datetime.date under/overflow.
Diffstat (limited to 'Lib/test/test_calendar.py')
-rw-r--r--Lib/test/test_calendar.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
index 6dad058..6c7cdd1 100644
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -502,6 +502,27 @@ class CalendarTestCase(unittest.TestCase):
# see #15421
list(calendar.Calendar().itermonthdates(datetime.MAXYEAR, 12))
+ def test_itermonthdays(self):
+ for firstweekday in range(7):
+ cal = calendar.Calendar(firstweekday)
+ # Test the extremes, see #28253 and #26650
+ for y, m in [(1, 1), (9999, 12)]:
+ days = list(cal.itermonthdays(y, m))
+ self.assertIn(len(days), (35, 42))
+ # Test a short month
+ cal = calendar.Calendar(firstweekday=3)
+ days = list(cal.itermonthdays(2001, 2))
+ self.assertEqual(days, list(range(1, 29)))
+
+ def test_itermonthdays2(self):
+ for firstweekday in range(7):
+ cal = calendar.Calendar(firstweekday)
+ # Test the extremes, see #28253 and #26650
+ for y, m in [(1, 1), (9999, 12)]:
+ days = list(cal.itermonthdays2(y, m))
+ self.assertEqual(days[0][1], firstweekday)
+ self.assertEqual(days[-1][1], (firstweekday - 1) % 7)
+
class MonthCalendarTestCase(unittest.TestCase):
def setUp(self):