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
ff0e8d21
Commit
ff0e8d21
authored
Aug 29, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #17974: Switch unittest from using getopt to using argparse.
parent
9a71181c
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
170 additions
and
177 deletions
+170
-177
Lib/unittest/__main__.py
Lib/unittest/__main__.py
+1
-2
Lib/unittest/main.py
Lib/unittest/main.py
+113
-137
Lib/unittest/test/test_discovery.py
Lib/unittest/test/test_discovery.py
+26
-29
Lib/unittest/test/test_program.py
Lib/unittest/test/test_program.py
+28
-9
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/unittest/__main__.py
View file @
ff0e8d21
...
...
@@ -13,7 +13,6 @@ if sys.argv[0].endswith("__main__.py"):
__unittest
=
True
from
.main
import
main
,
TestProgram
,
USAGE_AS_MAIN
TestProgram
.
USAGE
=
USAGE_AS_MAIN
from
.main
import
main
,
TestProgram
main
(
module
=
None
)
Lib/unittest/main.py
View file @
ff0e8d21
This diff is collapsed.
Click to expand it.
Lib/unittest/test/test_discovery.py
View file @
ff0e8d21
import
os
import
re
import
sys
from
test
import
support
import
unittest
class
TestableTestProgram
(
unittest
.
TestProgram
):
module
=
'__main__'
module
=
None
exit
=
True
defaultTest
=
failfast
=
catchbreak
=
buffer
=
None
verbosity
=
1
...
...
@@ -232,58 +233,54 @@ class TestDiscovery(unittest.TestCase):
program
=
TestableTestProgram
()
args
=
[]
def
do_discovery
(
argv
):
args
.
extend
(
argv
)
program
.
_do_discovery
=
do_discovery
program
.
_do_discovery
=
args
.
append
program
.
parseArgs
([
'something'
,
'discover'
])
self
.
assertEqual
(
args
,
[])
self
.
assertEqual
(
args
,
[
[]
])
args
[:]
=
[]
program
.
parseArgs
([
'something'
,
'discover'
,
'foo'
,
'bar'
])
self
.
assertEqual
(
args
,
[
'foo'
,
'bar'
])
self
.
assertEqual
(
args
,
[
[
'foo'
,
'bar'
]
])
def
test_command_line_handling_discover_by_default
(
self
):
program
=
TestableTestProgram
()
program
.
module
=
None
self
.
called
=
False
def
do_discovery
(
argv
):
self
.
called
=
True
self
.
assertEqual
(
argv
,
[])
program
.
_do_discovery
=
do_discovery
args
=
[]
program
.
_do_discovery
=
args
.
append
program
.
parseArgs
([
'something'
])
self
.
assertTrue
(
self
.
called
)
self
.
assertEqual
(
args
,
[[]])
self
.
assertEqual
(
program
.
verbosity
,
1
)
self
.
assertIs
(
program
.
buffer
,
False
)
self
.
assertIs
(
program
.
catchbreak
,
False
)
self
.
assertIs
(
program
.
failfast
,
False
)
def
test_command_line_handling_discover_by_default_with_options
(
self
):
program
=
TestableTestProgram
()
program
.
module
=
None
args
=
[
'something'
,
'-v'
,
'-b'
,
'-v'
,
'-c'
,
'-f'
]
self
.
called
=
False
def
do_discovery
(
argv
):
self
.
called
=
True
self
.
assertEqual
(
argv
,
args
[
1
:]
)
program
.
_do_discovery
=
do_discovery
program
.
parseArgs
(
args
)
self
.
assert
True
(
self
.
called
)
args
=
[]
program
.
_do_discovery
=
args
.
append
program
.
parseArgs
([
'something'
,
'-v'
,
'-b'
,
'-v'
,
'-c'
,
'-f'
])
self
.
assertEqual
(
args
,
[[]])
self
.
assertEqual
(
program
.
verbosity
,
2
)
self
.
assertIs
(
program
.
buffer
,
True
)
self
.
assertIs
(
program
.
catchbreak
,
True
)
self
.
assert
Is
(
program
.
failfast
,
True
)
def
test_command_line_handling_do_discovery_too_many_arguments
(
self
):
class
Stop
(
Exception
):
pass
def
usageExit
():
raise
Stop
program
=
TestableTestProgram
()
program
.
usageExit
=
usageExit
program
.
testLoader
=
None
with
self
.
assertRaises
(
Stop
):
with
support
.
captured_stderr
()
as
stderr
,
\
self
.
assertRaises
(
SystemExit
)
as
cm
:
# too many args
program
.
_do_discovery
([
'one'
,
'two'
,
'three'
,
'four'
])
self
.
assertEqual
(
cm
.
exception
.
args
,
(
2
,))
self
.
assertIn
(
'usage:'
,
stderr
.
getvalue
())
def
test_command_line_handling_do_discovery_uses_default_loader
(
self
):
program
=
object
.
__new__
(
unittest
.
TestProgram
)
program
.
_initArgParsers
()
class
Loader
(
object
):
args
=
[]
...
...
Lib/unittest/test/test_program.py
View file @
ff0e8d21
...
...
@@ -2,6 +2,7 @@ import io
import
os
import
sys
from
test
import
support
import
unittest
...
...
@@ -186,20 +187,38 @@ class TestCommandLineArgs(unittest.TestCase):
if
attr
==
'catch'
and
not
hasInstallHandler
:
continue
setattr
(
program
,
attr
,
None
)
program
.
parseArgs
([
None
])
self
.
assertIs
(
getattr
(
program
,
attr
),
False
)
false
=
[]
setattr
(
program
,
attr
,
false
)
program
.
parseArgs
([
None
])
self
.
assertIs
(
getattr
(
program
,
attr
),
false
)
true
=
[
42
]
setattr
(
program
,
attr
,
true
)
program
.
parseArgs
([
None
])
self
.
assertIs
(
getattr
(
program
,
attr
),
true
)
short_opt
=
'-%s'
%
arg
[
0
]
long_opt
=
'--%s'
%
arg
for
opt
in
short_opt
,
long_opt
:
setattr
(
program
,
attr
,
None
)
program
.
parseArgs
([
None
,
opt
])
self
.
assertTrue
(
getattr
(
program
,
attr
))
for
opt
in
short_opt
,
long_opt
:
not_none
=
object
()
setattr
(
program
,
attr
,
not_none
)
program
.
parseArgs
([
None
,
opt
])
self
.
assertEqual
(
getattr
(
program
,
attr
),
not_none
)
self
.
assertIs
(
getattr
(
program
,
attr
),
True
)
setattr
(
program
,
attr
,
False
)
with
support
.
captured_stderr
()
as
stderr
,
\
self
.
assertRaises
(
SystemExit
)
as
cm
:
program
.
parseArgs
([
None
,
opt
])
self
.
assertEqual
(
cm
.
exception
.
args
,
(
2
,))
setattr
(
program
,
attr
,
True
)
with
support
.
captured_stderr
()
as
stderr
,
\
self
.
assertRaises
(
SystemExit
)
as
cm
:
program
.
parseArgs
([
None
,
opt
])
self
.
assertEqual
(
cm
.
exception
.
args
,
(
2
,))
def
testWarning
(
self
):
"""Test the warnings argument"""
...
...
Misc/NEWS
View file @
ff0e8d21
...
...
@@ -51,6 +51,8 @@ Core and Builtins
Library
-------
- Issue #17974: Switch unittest from using getopt to using argparse.
- Issue #11798: TestSuite now drops references to own tests after execution.
- Issue #16611: http.cookie now correctly parses the '
secure
' and '
httponly
'
...
...
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