Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
256198a6
Commit
256198a6
authored
Feb 05, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #18982: Add tests for CLI of the calendar module.
parent
8f307447
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
3 deletions
+136
-3
Lib/test/test_calendar.py
Lib/test/test_calendar.py
+134
-3
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/test/test_calendar.py
View file @
256198a6
...
...
@@ -2,11 +2,22 @@ import calendar
import
unittest
from
test
import
test_support
from
test.script_helper
import
assert_python_ok
,
assert_python_failure
import
locale
import
datetime
import
os
result_2004_01_text
=
"""
\
January 2004
Mo Tu We Th Fr Sa Su
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
"""
result_2004_text
=
"""
result_2004_text
=
"""
\
2004
January February March
...
...
@@ -44,7 +55,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
=
"""
\
<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
...
...
@@ -460,6 +471,124 @@ class LeapdaysTestCase(unittest.TestCase):
self
.
assertEqual
(
calendar
.
leapdays
(
1997
,
2020
),
5
)
class
CommandLineTestCase
(
unittest
.
TestCase
):
def
run_ok
(
self
,
*
args
):
return
assert_python_ok
(
'-m'
,
'calendar'
,
*
args
)[
1
]
def
assertFailure
(
self
,
*
args
):
rc
,
stdout
,
stderr
=
assert_python_failure
(
'-m'
,
'calendar'
,
*
args
)
self
.
assertIn
(
b'Usage:'
,
stderr
)
self
.
assertEqual
(
rc
,
2
)
def
test_help
(
self
):
stdout
=
self
.
run_ok
(
'-h'
)
self
.
assertIn
(
b'Usage:'
,
stdout
)
self
.
assertIn
(
b'calendar.py'
,
stdout
)
self
.
assertIn
(
b'--help'
,
stdout
)
def
test_illegal_arguments
(
self
):
self
.
assertFailure
(
'-z'
)
#self.assertFailure('spam')
#self.assertFailure('2004', '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
)
def
test_output_year
(
self
):
stdout
=
self
.
run_ok
(
'2004'
)
self
.
assertEqual
(
stdout
.
strip
(),
result_2004_text
.
strip
())
def
test_output_month
(
self
):
stdout
=
self
.
run_ok
(
'2004'
,
'1'
)
self
.
assertEqual
(
stdout
.
strip
(),
result_2004_01_text
.
strip
())
def
test_option_encoding
(
self
):
self
.
assertFailure
(
'-e'
)
self
.
assertFailure
(
'--encoding'
)
stdout
=
self
.
run_ok
(
'--encoding'
,
'rot-13'
,
'2004'
)
self
.
assertEqual
(
stdout
.
strip
(),
result_2004_text
.
encode
(
'rot-13'
).
strip
())
def
test_option_locale
(
self
):
self
.
assertFailure
(
'-L'
)
self
.
assertFailure
(
'--locale'
)
self
.
assertFailure
(
'-L'
,
'en'
)
lang
,
enc
=
locale
.
getdefaultlocale
()
lang
=
lang
or
'C'
enc
=
enc
or
'UTF-8'
try
:
oldlocale
=
locale
.
getlocale
(
locale
.
LC_TIME
)
try
:
locale
.
setlocale
(
locale
.
LC_TIME
,
(
lang
,
enc
))
finally
:
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
)
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
)
def
test_option_lines
(
self
):
self
.
assertFailure
(
'-l'
)
self
.
assertFailure
(
'--lines'
)
self
.
assertFailure
(
'-l'
,
'spam'
)
stdout
=
self
.
run_ok
(
'--lines'
,
'2'
,
'2004'
)
self
.
assertIn
(
'December
\
n
\
n
Mo Tu We'
,
stdout
)
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
)
def
test_option_months
(
self
):
self
.
assertFailure
(
'-m'
)
self
.
assertFailure
(
'--month'
)
self
.
assertFailure
(
'-m'
,
'spam'
)
stdout
=
self
.
run_ok
(
'--months'
,
'1'
,
'2004'
)
self
.
assertIn
(
'
\
n
Mo Tu We Th Fr Sa Su
\
n
'
,
stdout
)
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
.
strip
(),
result_2004_text
.
strip
())
stdout
=
self
.
run_ok
(
'--type'
,
'html'
,
'2004'
)
self
.
assertEqual
(
stdout
[:
6
],
b'<?xml '
)
self
.
assertIn
(
b'<title>Calendar for 2004</title>'
,
stdout
)
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
)
def
test_html_output_year_encoding
(
self
):
stdout
=
self
.
run_ok
(
'-t'
,
'html'
,
'--encoding'
,
'ascii'
,
'2004'
)
self
.
assertEqual
(
stdout
.
strip
(),
result_2004_html
.
strip
())
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
)
def
test_main
():
test_support
.
run_unittest
(
OutputTestCase
,
...
...
@@ -468,8 +597,10 @@ def test_main():
SundayTestCase
,
MonthRangeTestCase
,
LeapdaysTestCase
,
CommandLineTestCase
,
)
if
__name__
==
"__main__"
:
test_main
()
unittest
.
main
()
Misc/NEWS
View file @
256198a6
...
...
@@ -98,6 +98,8 @@ Tools/Demos
Tests
-----
- Issue #18982: Add tests for CLI of the calendar module.
- Issue #19949: The test_xpickle test now tests compatibility with installed
Python 2.7 and reports skipped tests. Based on patch by Zachary Ware.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment