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
3a2b5419
Commit
3a2b5419
authored
Jan 11, 2008
by
Raymond Hettinger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Doctest results return a named tuple for readability
parent
064aeb0e
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
70 deletions
+76
-70
Lib/doctest.py
Lib/doctest.py
+15
-12
Lib/test/test_doctest.py
Lib/test/test_doctest.py
+58
-58
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/doctest.py
View file @
3a2b5419
...
...
@@ -99,6 +99,9 @@ import sys, traceback, inspect, linecache, os, re
import
unittest
,
difflib
,
pdb
,
tempfile
import
warnings
from
StringIO
import
StringIO
from
collections
import
namedtuple
TestResults
=
namedtuple
(
'TestResults'
,
'failed attempted'
)
# There are 4 basic classes:
# - Example: a <source, want> pair, plus an intra-docstring line number.
...
...
@@ -1028,10 +1031,10 @@ class DocTestRunner:
>>> tests.sort(key = lambda test: test.name)
>>> for test in tests:
... print test.name, '->', runner.run(test)
_TestClass ->
(0,
2)
_TestClass.__init__ ->
(0,
2)
_TestClass.get ->
(0,
2)
_TestClass.square ->
(0,
1)
_TestClass ->
TestResults(failed=0, attempted=
2)
_TestClass.__init__ ->
TestResults(failed=0, attempted=
2)
_TestClass.get ->
TestResults(failed=0, attempted=
2)
_TestClass.square ->
TestResults(failed=0, attempted=
1)
The `summarize` method prints a summary of all the test cases that
have been run by the runner, and returns an aggregated `(f, t)`
...
...
@@ -1046,7 +1049,7 @@ class DocTestRunner:
7 tests in 4 items.
7 passed and 0 failed.
Test passed.
(0,
7)
TestResults(failed=0, attempted=
7)
The aggregated number of tried examples and failed examples is
also available via the `tries` and `failures` attributes:
...
...
@@ -1289,7 +1292,7 @@ class DocTestRunner:
# Record and return the number of failures and tries.
self
.
__record_outcome
(
test
,
failures
,
tries
)
return
failures
,
tries
return
TestResults
(
failures
,
tries
)
def
__record_outcome
(
self
,
test
,
f
,
t
):
"""
...
...
@@ -1421,7 +1424,7 @@ class DocTestRunner:
print
"***Test Failed***"
,
totalf
,
"failures."
elif
verbose
:
print
"Test passed."
return
totalf
,
totalt
return
TestResults
(
totalf
,
totalt
)
#/////////////////////////////////////////////////////////////////
# Backward compatibility cruft to maintain doctest.master.
...
...
@@ -1692,7 +1695,7 @@ class DebugRunner(DocTestRunner):
... ''', {}, 'foo', 'foo.py', 0)
>>> runner.run(test)
(0,
1)
TestResults(failed=0, attempted=
1)
>>> test.globs
{}
...
...
@@ -1822,7 +1825,7 @@ def testmod(m=None, name=None, globs=None, verbose=None,
else
:
master
.
merge
(
runner
)
return
runner
.
failures
,
runner
.
tries
return
TestResults
(
runner
.
failures
,
runner
.
tries
)
def
testfile
(
filename
,
module_relative
=
True
,
name
=
None
,
package
=
None
,
globs
=
None
,
verbose
=
None
,
report
=
True
,
optionflags
=
0
,
...
...
@@ -1945,7 +1948,7 @@ def testfile(filename, module_relative=True, name=None, package=None,
else
:
master
.
merge
(
runner
)
return
runner
.
failures
,
runner
.
tries
return
TestResults
(
runner
.
failures
,
runner
.
tries
)
def
run_docstring_examples
(
f
,
globs
,
verbose
=
False
,
name
=
"NoName"
,
compileflags
=
None
,
optionflags
=
0
):
...
...
@@ -2004,7 +2007,7 @@ class Tester:
(
f
,
t
)
=
self
.
testrunner
.
run
(
test
)
if
self
.
verbose
:
print
f
,
"of"
,
t
,
"examples failed in string"
,
name
return
(
f
,
t
)
return
TestResults
(
f
,
t
)
def
rundoc
(
self
,
object
,
name
=
None
,
module
=
None
):
f
=
t
=
0
...
...
@@ -2013,7 +2016,7 @@ class Tester:
for
test
in
tests
:
(
f2
,
t2
)
=
self
.
testrunner
.
run
(
test
)
(
f
,
t
)
=
(
f
+
f2
,
t
+
t2
)
return
(
f
,
t
)
return
TestResults
(
f
,
t
)
def
rundict
(
self
,
d
,
name
,
module
=
None
):
import
types
...
...
Lib/test/test_doctest.py
View file @
3a2b5419
This diff is collapsed.
Click to expand it.
Misc/NEWS
View file @
3a2b5419
...
...
@@ -351,6 +351,9 @@ Core and builtins
Library
-------
- Doctest now returns results as a named tuple for readability:
(0, 7) --> TestResults(failed=0, attempted=7)
- Issue #846388. re.match is interruptible now, which is particularly
good for long regular expression matches.
...
...
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