mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
update calendar and test_calendar to 3.13.2
This commit is contained in:
1 parent
4094c5bfc9
commit
c7df344805
2 files changed
+238
-62
No files matched your search
Vendored
+30
-15
@@ -10,7 +10,6 @@ import datetime
|
||||
from enum import IntEnum, global_enum
|
||||
import locale as _locale
|
||||
from itertools import repeat
|
||||
import warnings
|
||||
|
||||
__all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
|
||||
"firstweekday", "isleap", "leapdays", "weekday", "monthrange",
|
||||
@@ -28,7 +27,9 @@ __all__ = ["IllegalMonthError", "IllegalWeekdayError", "setfirstweekday",
|
||||
error = ValueError
|
||||
|
||||
# Exceptions raised for bad input
|
||||
class IllegalMonthError(ValueError):
|
||||
# This is trick for backward compatibility. Since 3.13, we will raise IllegalMonthError instead of
|
||||
# IndexError for bad month number(out of 1-12). But we can't remove IndexError for backward compatibility.
|
||||
class IllegalMonthError(ValueError, IndexError):
|
||||
def __init__(self, month):
|
||||
self.month = month
|
||||
def __str__(self):
|
||||
@@ -44,6 +45,7 @@ class IllegalWeekdayError(ValueError):
|
||||
|
||||
def __getattr__(name):
|
||||
if name in ('January', 'February'):
|
||||
import warnings
|
||||
warnings.warn(f"The '{name}' attribute is deprecated, use '{name.upper()}' instead",
|
||||
DeprecationWarning, stacklevel=2)
|
||||
if name == 'January':
|
||||
@@ -158,11 +160,14 @@ def weekday(year, month, day):
|
||||
return Day(datetime.date(year, month, day).weekday())
|
||||
|
||||
|
||||
def monthrange(year, month):
|
||||
"""Return weekday (0-6 ~ Mon-Sun) and number of days (28-31) for
|
||||
year, month."""
|
||||
def _validate_month(month):
|
||||
if not 1 <= month <= 12:
|
||||
raise IllegalMonthError(month)
|
||||
|
||||
def monthrange(year, month):
|
||||
"""Return weekday of first day of month (0-6 ~ Mon-Sun)
|
||||
and number of days (28-31) for year, month."""
|
||||
_validate_month(month)
|
||||
day1 = weekday(year, month, 1)
|
||||
ndays = mdays[month] + (month == FEBRUARY and isleap(year))
|
||||
return day1, ndays
|
||||
@@ -370,6 +375,8 @@ class TextCalendar(Calendar):
|
||||
"""
|
||||
Return a formatted month name.
|
||||
"""
|
||||
_validate_month(themonth)
|
||||
|
||||
s = month_name[themonth]
|
||||
if withyear:
|
||||
s = "%s %r" % (s, theyear)
|
||||
@@ -500,6 +507,7 @@ class HTMLCalendar(Calendar):
|
||||
"""
|
||||
Return a month name as a table row.
|
||||
"""
|
||||
_validate_month(themonth)
|
||||
if withyear:
|
||||
s = '%s %s' % (month_name[themonth], theyear)
|
||||
else:
|
||||
@@ -585,8 +593,6 @@ class different_locale:
|
||||
_locale.setlocale(_locale.LC_TIME, self.locale)
|
||||
|
||||
def __exit__(self, *args):
|
||||
if self.oldlocale is None:
|
||||
return
|
||||
_locale.setlocale(_locale.LC_TIME, self.oldlocale)
|
||||
|
||||
|
||||
@@ -690,7 +696,7 @@ def timegm(tuple):
|
||||
return seconds
|
||||
|
||||
|
||||
def main(args):
|
||||
def main(args=None):
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
textgroup = parser.add_argument_group('text only arguments')
|
||||
@@ -736,10 +742,15 @@ def main(args):
|
||||
choices=("text", "html"),
|
||||
help="output type (text or html)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"-f", "--first-weekday",
|
||||
type=int, default=0,
|
||||
help="weekday (0 is Monday, 6 is Sunday) to start each week (default 0)"
|
||||
)
|
||||
parser.add_argument(
|
||||
"year",
|
||||
nargs='?', type=int,
|
||||
help="year number (1-9999)"
|
||||
help="year number"
|
||||
)
|
||||
parser.add_argument(
|
||||
"month",
|
||||
@@ -747,7 +758,7 @@ def main(args):
|
||||
help="month number (1-12, text only)"
|
||||
)
|
||||
|
||||
options = parser.parse_args(args[1:])
|
||||
options = parser.parse_args(args)
|
||||
|
||||
if options.locale and not options.encoding:
|
||||
parser.error("if --locale is specified --encoding is required")
|
||||
@@ -756,10 +767,14 @@ def main(args):
|
||||
locale = options.locale, options.encoding
|
||||
|
||||
if options.type == "html":
|
||||
if options.month:
|
||||
parser.error("incorrect number of arguments")
|
||||
sys.exit(1)
|
||||
if options.locale:
|
||||
cal = LocaleHTMLCalendar(locale=locale)
|
||||
else:
|
||||
cal = HTMLCalendar()
|
||||
cal.setfirstweekday(options.first_weekday)
|
||||
encoding = options.encoding
|
||||
if encoding is None:
|
||||
encoding = sys.getdefaultencoding()
|
||||
@@ -767,20 +782,20 @@ def main(args):
|
||||
write = sys.stdout.buffer.write
|
||||
if options.year is None:
|
||||
write(cal.formatyearpage(datetime.date.today().year, **optdict))
|
||||
elif options.month is None:
|
||||
write(cal.formatyearpage(options.year, **optdict))
|
||||
else:
|
||||
parser.error("incorrect number of arguments")
|
||||
sys.exit(1)
|
||||
write(cal.formatyearpage(options.year, **optdict))
|
||||
else:
|
||||
if options.locale:
|
||||
cal = LocaleTextCalendar(locale=locale)
|
||||
else:
|
||||
cal = TextCalendar()
|
||||
cal.setfirstweekday(options.first_weekday)
|
||||
optdict = dict(w=options.width, l=options.lines)
|
||||
if options.month is None:
|
||||
optdict["c"] = options.spacing
|
||||
optdict["m"] = options.months
|
||||
if options.month is not None:
|
||||
_validate_month(options.month)
|
||||
if options.year is None:
|
||||
result = cal.formatyear(datetime.date.today().year, **optdict)
|
||||
elif options.month is None:
|
||||
@@ -795,4 +810,4 @@ def main(args):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main(sys.argv)
|
||||
main()
|
||||
Vendored
+208
-47
@@ -3,12 +3,13 @@ import unittest
|
||||
|
||||
from test import support
|
||||
from test.support.script_helper import assert_python_ok, assert_python_failure
|
||||
import time
|
||||
import locale
|
||||
import sys
|
||||
import contextlib
|
||||
import datetime
|
||||
import io
|
||||
import locale
|
||||
import os
|
||||
import warnings
|
||||
import sys
|
||||
import time
|
||||
|
||||
# From https://en.wikipedia.org/wiki/Leap_year_starting_on_Saturday
|
||||
result_0_02_text = """\
|
||||
@@ -456,6 +457,11 @@ class OutputTestCase(unittest.TestCase):
|
||||
calendar.TextCalendar().formatmonth(0, 2),
|
||||
result_0_02_text
|
||||
)
|
||||
def test_formatmonth_with_invalid_month(self):
|
||||
with self.assertRaises(calendar.IllegalMonthError):
|
||||
calendar.TextCalendar().formatmonth(2017, 13)
|
||||
with self.assertRaises(calendar.IllegalMonthError):
|
||||
calendar.TextCalendar().formatmonth(2017, -1)
|
||||
|
||||
def test_formatmonthname_with_year(self):
|
||||
self.assertEqual(
|
||||
@@ -550,26 +556,92 @@ class CalendarTestCase(unittest.TestCase):
|
||||
# verify it "acts like a sequence" in two forms of iteration
|
||||
self.assertEqual(value[::-1], list(reversed(value)))
|
||||
|
||||
def test_locale_calendars(self):
|
||||
def test_locale_text_calendar(self):
|
||||
try:
|
||||
cal = calendar.LocaleTextCalendar(locale='')
|
||||
local_weekday = cal.formatweekday(1, 10)
|
||||
local_weekday_abbr = cal.formatweekday(1, 3)
|
||||
local_month = cal.formatmonthname(2010, 10, 10)
|
||||
except locale.Error:
|
||||
# cannot set the system default locale -- skip rest of test
|
||||
raise unittest.SkipTest('cannot set the system default locale')
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_weekday_abbr, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
self.assertEqual(len(local_weekday), 10)
|
||||
self.assertEqual(len(local_weekday_abbr), 3)
|
||||
self.assertGreaterEqual(len(local_month), 10)
|
||||
|
||||
cal = calendar.LocaleTextCalendar(locale=None)
|
||||
local_weekday = cal.formatweekday(1, 10)
|
||||
local_weekday_abbr = cal.formatweekday(1, 3)
|
||||
local_month = cal.formatmonthname(2010, 10, 10)
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_weekday_abbr, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
self.assertEqual(len(local_weekday), 10)
|
||||
self.assertEqual(len(local_weekday_abbr), 3)
|
||||
self.assertGreaterEqual(len(local_month), 10)
|
||||
|
||||
cal = calendar.LocaleTextCalendar(locale='C')
|
||||
local_weekday = cal.formatweekday(1, 10)
|
||||
local_weekday_abbr = cal.formatweekday(1, 3)
|
||||
local_month = cal.formatmonthname(2010, 10, 10)
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_weekday_abbr, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
self.assertEqual(len(local_weekday), 10)
|
||||
self.assertEqual(len(local_weekday_abbr), 3)
|
||||
self.assertGreaterEqual(len(local_month), 10)
|
||||
|
||||
def test_locale_html_calendar(self):
|
||||
try:
|
||||
cal = calendar.LocaleHTMLCalendar(locale='')
|
||||
local_weekday = cal.formatweekday(1)
|
||||
local_month = cal.formatmonthname(2010, 10)
|
||||
except locale.Error:
|
||||
# cannot set the system default locale -- skip rest of test
|
||||
raise unittest.SkipTest('cannot set the system default locale')
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
|
||||
cal = calendar.LocaleHTMLCalendar(locale=None)
|
||||
local_weekday = cal.formatweekday(1)
|
||||
local_month = cal.formatmonthname(2010, 10)
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
|
||||
cal = calendar.LocaleHTMLCalendar(locale='C')
|
||||
local_weekday = cal.formatweekday(1)
|
||||
local_month = cal.formatmonthname(2010, 10)
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
|
||||
def test_locale_calendars_reset_locale_properly(self):
|
||||
# ensure that Locale{Text,HTML}Calendar resets the locale properly
|
||||
# (it is still not thread-safe though)
|
||||
old_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
|
||||
try:
|
||||
cal = calendar.LocaleTextCalendar(locale='')
|
||||
local_weekday = cal.formatweekday(1, 10)
|
||||
local_weekday_abbr = cal.formatweekday(1, 3)
|
||||
local_month = cal.formatmonthname(2010, 10, 10)
|
||||
except locale.Error:
|
||||
# cannot set the system default locale -- skip rest of test
|
||||
raise unittest.SkipTest('cannot set the system default locale')
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_weekday_abbr, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
self.assertEqual(len(local_weekday), 10)
|
||||
self.assertEqual(len(local_weekday_abbr), 3)
|
||||
self.assertGreaterEqual(len(local_month), 10)
|
||||
|
||||
cal = calendar.LocaleHTMLCalendar(locale='')
|
||||
local_weekday = cal.formatweekday(1)
|
||||
local_month = cal.formatmonthname(2010, 10)
|
||||
self.assertIsInstance(local_weekday, str)
|
||||
self.assertIsInstance(local_month, str)
|
||||
|
||||
new_october = calendar.TextCalendar().formatmonthname(2010, 10, 10)
|
||||
self.assertEqual(old_october, new_october)
|
||||
|
||||
@@ -590,6 +662,21 @@ class CalendarTestCase(unittest.TestCase):
|
||||
except locale.Error:
|
||||
raise unittest.SkipTest('cannot set the en_US locale')
|
||||
|
||||
def test_locale_calendar_formatmonthname(self):
|
||||
try:
|
||||
# formatmonthname uses the same month names regardless of the width argument.
|
||||
cal = calendar.LocaleTextCalendar(locale='en_US')
|
||||
# For too short widths, a full name (with year) is used.
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=False), "June")
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 2, withyear=True), "June 2022")
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 3, withyear=False), "June")
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 3, withyear=True), "June 2022")
|
||||
# For long widths, a centered name is used.
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 10, withyear=False), " June ")
|
||||
self.assertEqual(cal.formatmonthname(2022, 6, 15, withyear=True), " June 2022 ")
|
||||
except locale.Error:
|
||||
raise unittest.SkipTest('cannot set the en_US locale')
|
||||
|
||||
def test_locale_html_calendar_custom_css_class_month_name(self):
|
||||
try:
|
||||
cal = calendar.LocaleHTMLCalendar(locale='')
|
||||
@@ -848,46 +935,104 @@ def conv(s):
|
||||
return s.replace('\n', os.linesep).encode()
|
||||
|
||||
class CommandLineTestCase(unittest.TestCase):
|
||||
def run_ok(self, *args):
|
||||
def setUp(self):
|
||||
self.runners = [self.run_cli_ok, self.run_cmd_ok]
|
||||
|
||||
@contextlib.contextmanager
|
||||
def captured_stdout_with_buffer(self):
|
||||
orig_stdout = sys.stdout
|
||||
buffer = io.BytesIO()
|
||||
sys.stdout = io.TextIOWrapper(buffer)
|
||||
try:
|
||||
yield sys.stdout
|
||||
finally:
|
||||
sys.stdout.flush()
|
||||
sys.stdout.buffer.seek(0)
|
||||
sys.stdout = orig_stdout
|
||||
|
||||
@contextlib.contextmanager
|
||||
def captured_stderr_with_buffer(self):
|
||||
orig_stderr = sys.stderr
|
||||
buffer = io.BytesIO()
|
||||
sys.stderr = io.TextIOWrapper(buffer)
|
||||
try:
|
||||
yield sys.stderr
|
||||
finally:
|
||||
sys.stderr.flush()
|
||||
sys.stderr.buffer.seek(0)
|
||||
sys.stderr = orig_stderr
|
||||
|
||||
def run_cli_ok(self, *args):
|
||||
with self.captured_stdout_with_buffer() as stdout:
|
||||
calendar.main(args)
|
||||
return stdout.buffer.read()
|
||||
|
||||
def run_cmd_ok(self, *args):
|
||||
return assert_python_ok('-m', 'calendar', *args)[1]
|
||||
|
||||
def assertFailure(self, *args):
|
||||
def assertCLIFails(self, *args):
|
||||
with self.captured_stderr_with_buffer() as stderr:
|
||||
self.assertRaises(SystemExit, calendar.main, args)
|
||||
stderr = stderr.buffer.read()
|
||||
self.assertIn(b'usage:', stderr)
|
||||
return stderr
|
||||
|
||||
def assertCmdFails(self, *args):
|
||||
rc, stdout, stderr = assert_python_failure('-m', 'calendar', *args)
|
||||
self.assertIn(b'usage:', stderr)
|
||||
self.assertEqual(rc, 2)
|
||||
return rc, stdout, stderr
|
||||
|
||||
def assertFailure(self, *args):
|
||||
self.assertCLIFails(*args)
|
||||
self.assertCmdFails(*args)
|
||||
|
||||
def test_help(self):
|
||||
stdout = self.run_ok('-h')
|
||||
stdout = self.run_cmd_ok('-h')
|
||||
self.assertIn(b'usage:', stdout)
|
||||
self.assertIn(b'calendar.py', stdout)
|
||||
self.assertIn(b'--help', stdout)
|
||||
|
||||
# special case: stdout but sys.exit()
|
||||
with self.captured_stdout_with_buffer() as output:
|
||||
self.assertRaises(SystemExit, calendar.main, ['-h'])
|
||||
output = output.buffer.read()
|
||||
self.assertIn(b'usage:', output)
|
||||
self.assertIn(b'--help', output)
|
||||
|
||||
def test_illegal_arguments(self):
|
||||
self.assertFailure('-z')
|
||||
self.assertFailure('spam')
|
||||
self.assertFailure('2004', 'spam')
|
||||
self.assertFailure('2004', '1', 'spam')
|
||||
self.assertFailure('2004', '1', '1')
|
||||
self.assertFailure('2004', '1', '1', 'spam')
|
||||
self.assertFailure('-t', 'html', '2004', '1')
|
||||
|
||||
def test_output_current_year(self):
|
||||
stdout = self.run_ok()
|
||||
year = datetime.datetime.now().year
|
||||
self.assertIn((' %s' % year).encode(), stdout)
|
||||
self.assertIn(b'January', stdout)
|
||||
self.assertIn(b'Mo Tu We Th Fr Sa Su', stdout)
|
||||
for run in self.runners:
|
||||
output = run()
|
||||
year = datetime.datetime.now().year
|
||||
self.assertIn(conv(' %s' % year), output)
|
||||
self.assertIn(b'January', output)
|
||||
self.assertIn(b'Mo Tu We Th Fr Sa Su', output)
|
||||
|
||||
def test_output_year(self):
|
||||
stdout = self.run_ok('2004')
|
||||
self.assertEqual(stdout, conv(result_2004_text))
|
||||
for run in self.runners:
|
||||
output = run('2004')
|
||||
self.assertEqual(output, conv(result_2004_text))
|
||||
|
||||
def test_output_month(self):
|
||||
stdout = self.run_ok('2004', '1')
|
||||
self.assertEqual(stdout, conv(result_2004_01_text))
|
||||
for run in self.runners:
|
||||
output = run('2004', '1')
|
||||
self.assertEqual(output, conv(result_2004_01_text))
|
||||
|
||||
def test_option_encoding(self):
|
||||
self.assertFailure('-e')
|
||||
self.assertFailure('--encoding')
|
||||
stdout = self.run_ok('--encoding', 'utf-16-le', '2004')
|
||||
self.assertEqual(stdout, result_2004_text.encode('utf-16-le'))
|
||||
for run in self.runners:
|
||||
output = run('--encoding', 'utf-16-le', '2004')
|
||||
self.assertEqual(output, result_2004_text.encode('utf-16-le'))
|
||||
|
||||
def test_option_locale(self):
|
||||
self.assertFailure('-L')
|
||||
@@ -905,66 +1050,75 @@ class CommandLineTestCase(unittest.TestCase):
|
||||
locale.setlocale(locale.LC_TIME, oldlocale)
|
||||
except (locale.Error, ValueError):
|
||||
self.skipTest('cannot set the system default locale')
|
||||
stdout = self.run_ok('--locale', lang, '--encoding', enc, '2004')
|
||||
self.assertIn('2004'.encode(enc), stdout)
|
||||
for run in self.runners:
|
||||
for type in ('text', 'html'):
|
||||
output = run(
|
||||
'--type', type, '--locale', lang, '--encoding', enc, '2004'
|
||||
)
|
||||
self.assertIn('2004'.encode(enc), output)
|
||||
|
||||
def test_option_width(self):
|
||||
self.assertFailure('-w')
|
||||
self.assertFailure('--width')
|
||||
self.assertFailure('-w', 'spam')
|
||||
stdout = self.run_ok('--width', '3', '2004')
|
||||
self.assertIn(b'Mon Tue Wed Thu Fri Sat Sun', stdout)
|
||||
for run in self.runners:
|
||||
output = run('--width', '3', '2004')
|
||||
self.assertIn(b'Mon Tue Wed Thu Fri Sat Sun', output)
|
||||
|
||||
def test_option_lines(self):
|
||||
self.assertFailure('-l')
|
||||
self.assertFailure('--lines')
|
||||
self.assertFailure('-l', 'spam')
|
||||
stdout = self.run_ok('--lines', '2', '2004')
|
||||
self.assertIn(conv('December\n\nMo Tu We'), stdout)
|
||||
for run in self.runners:
|
||||
output = run('--lines', '2', '2004')
|
||||
self.assertIn(conv('December\n\nMo Tu We'), output)
|
||||
|
||||
def test_option_spacing(self):
|
||||
self.assertFailure('-s')
|
||||
self.assertFailure('--spacing')
|
||||
self.assertFailure('-s', 'spam')
|
||||
stdout = self.run_ok('--spacing', '8', '2004')
|
||||
self.assertIn(b'Su Mo', stdout)
|
||||
for run in self.runners:
|
||||
output = run('--spacing', '8', '2004')
|
||||
self.assertIn(b'Su Mo', output)
|
||||
|
||||
def test_option_months(self):
|
||||
self.assertFailure('-m')
|
||||
self.assertFailure('--month')
|
||||
self.assertFailure('-m', 'spam')
|
||||
stdout = self.run_ok('--months', '1', '2004')
|
||||
self.assertIn(conv('\nMo Tu We Th Fr Sa Su\n'), stdout)
|
||||
for run in self.runners:
|
||||
output = run('--months', '1', '2004')
|
||||
self.assertIn(conv('\nMo Tu We Th Fr Sa Su\n'), output)
|
||||
|
||||
def test_option_type(self):
|
||||
self.assertFailure('-t')
|
||||
self.assertFailure('--type')
|
||||
self.assertFailure('-t', 'spam')
|
||||
stdout = self.run_ok('--type', 'text', '2004')
|
||||
self.assertEqual(stdout, conv(result_2004_text))
|
||||
stdout = self.run_ok('--type', 'html', '2004')
|
||||
self.assertEqual(stdout[:6], b'<?xml ')
|
||||
self.assertIn(b'<title>Calendar for 2004</title>', stdout)
|
||||
for run in self.runners:
|
||||
output = run('--type', 'text', '2004')
|
||||
self.assertEqual(output, conv(result_2004_text))
|
||||
output = run('--type', 'html', '2004')
|
||||
self.assertEqual(output[:6], b'<?xml ')
|
||||
self.assertIn(b'<title>Calendar for 2004</title>', output)
|
||||
|
||||
def test_html_output_current_year(self):
|
||||
stdout = self.run_ok('--type', 'html')
|
||||
year = datetime.datetime.now().year
|
||||
self.assertIn(('<title>Calendar for %s</title>' % year).encode(),
|
||||
stdout)
|
||||
self.assertIn(b'<tr><th colspan="7" class="month">January</th></tr>',
|
||||
stdout)
|
||||
for run in self.runners:
|
||||
output = run('--type', 'html')
|
||||
year = datetime.datetime.now().year
|
||||
self.assertIn(('<title>Calendar for %s</title>' % year).encode(), output)
|
||||
self.assertIn(b'<tr><th colspan="7" class="month">January</th></tr>', output)
|
||||
|
||||
def test_html_output_year_encoding(self):
|
||||
stdout = self.run_ok('-t', 'html', '--encoding', 'ascii', '2004')
|
||||
self.assertEqual(stdout,
|
||||
result_2004_html.format(**default_format).encode('ascii'))
|
||||
for run in self.runners:
|
||||
output = run('-t', 'html', '--encoding', 'ascii', '2004')
|
||||
self.assertEqual(output, result_2004_html.format(**default_format).encode('ascii'))
|
||||
|
||||
def test_html_output_year_css(self):
|
||||
self.assertFailure('-t', 'html', '-c')
|
||||
self.assertFailure('-t', 'html', '--css')
|
||||
stdout = self.run_ok('-t', 'html', '--css', 'custom.css', '2004')
|
||||
self.assertIn(b'<link rel="stylesheet" type="text/css" '
|
||||
b'href="custom.css" />', stdout)
|
||||
for run in self.runners:
|
||||
output = run('-t', 'html', '--css', 'custom.css', '2004')
|
||||
self.assertIn(b'<link rel="stylesheet" type="text/css" '
|
||||
b'href="custom.css" />', output)
|
||||
|
||||
|
||||
class MiscTestCase(unittest.TestCase):
|
||||
@@ -972,7 +1126,7 @@ class MiscTestCase(unittest.TestCase):
|
||||
not_exported = {
|
||||
'mdays', 'January', 'February', 'EPOCH',
|
||||
'different_locale', 'c', 'prweek', 'week', 'format',
|
||||
'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth'}
|
||||
'formatstring', 'main', 'monthlen', 'prevmonth', 'nextmonth', ""}
|
||||
support.check__all__(self, calendar, not_exported=not_exported)
|
||||
|
||||
|
||||
@@ -1000,6 +1154,13 @@ class TestSubClassingCase(unittest.TestCase):
|
||||
self.assertIn('class="text-center month"',
|
||||
self.cal.formatmonth(2017, 5))
|
||||
|
||||
def test_formatmonth_with_invalid_month(self):
|
||||
with self.assertRaises(calendar.IllegalMonthError):
|
||||
self.cal.formatmonth(2017, 13)
|
||||
with self.assertRaises(calendar.IllegalMonthError):
|
||||
self.cal.formatmonth(2017, -1)
|
||||
|
||||
|
||||
def test_formatweek(self):
|
||||
weeks = self.cal.monthdays2calendar(2017, 5)
|
||||
self.assertIn('class="wed text-nowrap"', self.cal.formatweek(weeks[0]))
|
||||
|
||||
Reference in new issue
Block a user