aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_calendar.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_calendar.py')
-rw-r--r--Lib/test/test_calendar.py31
1 files changed, 24 insertions, 7 deletions
diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py
index 0f91d295903..948a1197b9c 100644
--- a/Lib/test/test_calendar.py
+++ b/Lib/test/test_calendar.py
@@ -1,11 +1,12 @@
import calendar
import unittest
-from test import test_support
+from test import support
+from test.script_helper import assert_python_ok
+import time
import locale
import datetime
-
result_2004_text = """
2004
@@ -196,9 +197,11 @@ class OutputTestCase(unittest.TestCase):
)
def test_output_htmlcalendar(self):
+ encoding = 'ascii'
+ cal = calendar.HTMLCalendar()
self.assertEqual(
- calendar.HTMLCalendar().formatyearpage(2004).strip(),
- result_2004_html.strip()
+ cal.formatyearpage(2004, encoding=encoding).strip(b' \t\n'),
+ result_2004_html.strip(' \t\n').encode(encoding)
)
@@ -214,7 +217,7 @@ class CalendarTestCase(unittest.TestCase):
self.assertEqual(calendar.isleap(2003), 0)
def test_setfirstweekday(self):
- self.assertRaises(ValueError, calendar.setfirstweekday, 'flabber')
+ self.assertRaises(TypeError, calendar.setfirstweekday, 'flabber')
self.assertRaises(ValueError, calendar.setfirstweekday, -1)
self.assertRaises(ValueError, calendar.setfirstweekday, 200)
orig = calendar.firstweekday()
@@ -280,7 +283,7 @@ class MonthCalendarTestCase(unittest.TestCase):
def check_weeks(self, year, month, weeks):
cal = calendar.monthcalendar(year, month)
self.assertEqual(len(cal), len(weeks))
- for i in xrange(len(weeks)):
+ for i in range(len(weeks)):
self.assertEqual(weeks[i], sum(day != 0 for day in cal[i]))
@@ -399,6 +402,13 @@ class SundayTestCase(MonthCalendarTestCase):
# A 31-day december starting on friday (2+7+7+7+7+1 days)
self.check_weeks(1995, 12, (2, 7, 7, 7, 7, 1))
+class TimegmTestCase(unittest.TestCase):
+ TIMESTAMPS = [0, 10, 100, 1000, 10000, 100000, 1000000,
+ 1234567890, 1262304000, 1275785153,]
+ def test_timegm(self):
+ for secs in self.TIMESTAMPS:
+ tuple = time.gmtime(secs)
+ self.assertEqual(secs, calendar.timegm(tuple))
class MonthRangeTestCase(unittest.TestCase):
def test_january(self):
@@ -448,14 +458,21 @@ class LeapdaysTestCase(unittest.TestCase):
self.assertEqual(calendar.leapdays(1997,2020), 5)
+class ConsoleOutputTestCase(unittest.TestCase):
+ def test_outputs_bytes(self):
+ (return_code, stdout, stderr) = assert_python_ok('-m', 'calendar', '--type=html', '2010')
+ self.assertEqual(stdout[:6], b'<?xml ')
+
def test_main():
- test_support.run_unittest(
+ support.run_unittest(
OutputTestCase,
CalendarTestCase,
MondayTestCase,
SundayTestCase,
+ TimegmTestCase,
MonthRangeTestCase,
LeapdaysTestCase,
+ ConsoleOutputTestCase
)