diff --git a/Lib/test/test_calendar.py b/Lib/test/test_calendar.py index f680b52f097..9193857197b 100644 --- a/Lib/test/test_calendar.py +++ b/Lib/test/test_calendar.py @@ -2,13 +2,14 @@ import calendar import unittest from test import support -from test.script_helper import assert_python_ok +from test.script_helper import assert_python_ok, assert_python_failure import time import locale import sys import datetime +import os -result_2004_01_text = """ +result_2004_01_text = """\ January 2004 Mo Tu We Th Fr Sa Su 1 2 3 4 @@ -18,7 +19,7 @@ Mo Tu We Th Fr Sa Su 26 27 28 29 30 31 """ -result_2004_text = """ +result_2004_text = """\ 2004 January February March @@ -56,7 +57,7 @@ Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su 25 26 27 28 29 30 31 29 30 27 28 29 30 31 """ -result_2004_html = """ +result_2004_html = """\ @@ -327,8 +328,8 @@ class OutputTestCase(unittest.TestCase): def check_htmlcalendar_encoding(self, req, res): cal = calendar.HTMLCalendar() self.assertEqual( - cal.formatyearpage(2004, encoding=req).strip(b' \t\n'), - (result_2004_html % {'e': res}).strip(' \t\n').encode(res) + cal.formatyearpage(2004, encoding=req), + (result_2004_html % {'e': res}).encode(res) ) def test_output(self): @@ -339,8 +340,8 @@ class OutputTestCase(unittest.TestCase): def test_output_textcalendar(self): self.assertEqual( - calendar.TextCalendar().formatyear(2004).strip(), - result_2004_text.strip() + calendar.TextCalendar().formatyear(2004), + result_2004_text ) def test_output_htmlcalendar_encoding_ascii(self): @@ -383,8 +384,8 @@ class OutputTestCase(unittest.TestCase): def test_formatmonth(self): self.assertEqual( - calendar.TextCalendar().formatmonth(2004, 1).strip(), - result_2004_01_text.strip() + calendar.TextCalendar().formatmonth(2004, 1), + result_2004_01_text ) def test_formatmonthname_with_year(self): @@ -692,23 +693,127 @@ 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'Calendar for 2004', stdout) + + def test_html_output_current_year(self): + stdout = self.run_ok('--type', 'html') + year = datetime.datetime.now().year + self.assertIn(('