Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
1404860c
Commit
1404860c
authored
Jan 30, 2003
by
Fred Drake
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an option to report how long the slowest of the tests took.
parent
14e11016
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
2 deletions
+67
-2
utilities/testrunner.py
utilities/testrunner.py
+67
-2
No files found.
utilities/testrunner.py
View file @
1404860c
...
...
@@ -24,6 +24,7 @@ import getopt
import
imp
import
os
import
sys
import
time
import
traceback
import
unittest
...
...
@@ -212,6 +213,57 @@ class TestRunner:
print
>>
sys
.
stderr
,
'*** Restoring directory to:'
,
working_dir
os
.
chdir
(
working_dir
)
class
TimingTestResult
(
unittest
.
_TextTestResult
):
def
__init__
(
self
,
*
args
,
**
kw
):
self
.
timings
=
[]
unittest
.
_TextTestResult
.
__init__
(
self
,
*
args
,
**
kw
)
def
startTest
(
self
,
test
):
unittest
.
_TextTestResult
.
startTest
(
self
,
test
)
self
.
_t2
=
None
self
.
_t1
=
time
.
time
()
def
stopTest
(
self
,
test
):
t2
=
time
.
time
()
if
self
.
_t2
is
not
None
:
t2
=
self
.
_t2
t
=
t2
-
self
.
_t1
self
.
timings
.
append
((
t
,
str
(
test
)))
unittest
.
_TextTestResult
.
stopTest
(
self
,
test
)
def
addSuccess
(
self
,
test
):
self
.
_t2
=
time
.
time
()
unittest
.
_TextTestResult
.
addSuccess
(
self
,
test
)
def
addError
(
self
,
test
,
err
):
self
.
_t2
=
time
.
time
()
unittest
.
_TextTestResult
.
addError
(
self
,
test
,
err
)
def
addFailure
(
self
,
test
,
err
):
self
.
_t2
=
time
.
time
()
unittest
.
_TextTestResult
.
addFailure
(
self
,
test
,
err
)
class
TimingTestRunner
(
unittest
.
TextTestRunner
):
def
_makeResult
(
self
):
r
=
TimingTestResult
(
self
.
stream
,
self
.
descriptions
,
self
.
verbosity
)
self
.
timings
=
r
.
timings
return
r
class
TestTimer
(
TestRunner
):
def
createTestRunner
(
self
):
return
TimingTestRunner
(
stream
=
sys
.
stderr
,
verbosity
=
self
.
verbosity
)
def
reportTimes
(
self
,
num
):
r
=
self
.
getTestRunner
()
r
.
timings
.
sort
()
for
item
in
r
.
timings
[
-
num
:]:
print
"%.1f %s"
%
item
def
remove_stale_bytecode
(
arg
,
dirname
,
names
):
names
=
map
(
os
.
path
.
normcase
,
names
)
for
name
in
names
:
...
...
@@ -279,6 +331,9 @@ def main(args):
Output test results to the specified file rather than
to stderr.
-t N
Report time taken by the most expensive N tests.
-h
Display usage information.
"""
...
...
@@ -289,8 +344,9 @@ def main(args):
verbosity
=
VERBOSE
mega_suite
=
True
set_python_path
=
True
timed
=
0
options
,
arg
=
getopt
.
getopt
(
args
,
'amPhd:f:v:qMo:'
)
options
,
arg
=
getopt
.
getopt
(
args
,
'amPhd:f:v:qMo:
t:
'
)
if
not
options
:
err_exit
(
usage_msg
)
for
name
,
value
in
options
:
...
...
@@ -314,6 +370,9 @@ def main(args):
verbosity
=
int
(
value
)
elif
name
==
'-q'
:
verbosity
=
1
elif
name
==
'-t'
:
timed
=
int
(
value
)
assert
timed
>=
0
elif
name
==
'-o'
:
f
=
open
(
value
,
'w'
)
sys
.
stderr
=
f
...
...
@@ -322,7 +381,10 @@ def main(args):
os
.
path
.
walk
(
os
.
curdir
,
remove_stale_bytecode
,
None
)
testrunner
=
TestRunner
(
os
.
getcwd
(),
verbosity
,
mega_suite
)
if
timed
:
testrunner
=
TestTimer
(
os
.
getcwd
(),
verbosity
,
mega_suite
)
else
:
testrunner
=
TestRunner
(
os
.
getcwd
(),
verbosity
,
mega_suite
)
if
set_python_path
:
script
=
sys
.
argv
[
0
]
...
...
@@ -348,6 +410,9 @@ def main(args):
elif
filename
:
testrunner
.
runFile
(
filename
)
if
timed
:
testrunner
.
reportTimes
(
timed
)
## Report overall errors / failures if there were any
fails
=
reduce
(
lambda
x
,
y
:
x
+
len
(
y
.
failures
),
testrunner
.
results
,
0
)
errs
=
reduce
(
lambda
x
,
y
:
x
+
len
(
y
.
errors
),
testrunner
.
results
,
0
)
...
...
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