[Zope3-checkins]
SVN: zope.testing/trunk/src/zope/testing/testrunner
Refactor time formatting into a function that's reused. A
side effect is that
Marius Gedminas
marius at pov.lt
Thu Jul 19 09:41:48 EDT 2007
Log message for revision 78153:
Refactor time formatting into a function that's reused. A side effect is that
all times are now colorized with -c (which I planned to do eventually).
Changed:
U zope.testing/trunk/src/zope/testing/testrunner-colors.txt
U zope.testing/trunk/src/zope/testing/testrunner.py
-=-
Modified: zope.testing/trunk/src/zope/testing/testrunner-colors.txt
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner-colors.txt 2007-07-19 11:33:40 UTC (rev 78152)
+++ zope.testing/trunk/src/zope/testing/testrunner-colors.txt 2007-07-19 13:41:48 UTC (rev 78153)
@@ -48,14 +48,14 @@
>>> sys.argv = 'test --layer 122 -c'.split()
>>> testrunner.run(defaults)
{normal}Running samplelayers.Layer122 tests:{normal}
- Set up samplelayers.Layer1 in 0.000 seconds.
- Set up samplelayers.Layer12 in 0.000 seconds.
- Set up samplelayers.Layer122 in 0.000 seconds.
+ Set up samplelayers.Layer1 in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer12 in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer122 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.007{normal} seconds.{normal}
{normal}Tearing down left over layers:{normal}
- Tear down samplelayers.Layer122 in 0.000 seconds.
- Tear down samplelayers.Layer12 in 0.000 seconds.
- Tear down samplelayers.Layer1 in 0.000 seconds.
+ Tear down samplelayers.Layer122 in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layer12 in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layer1 in {green}0.000{normal} seconds.
False
A failed test run highlights the failures in red:
@@ -133,36 +133,36 @@
<BLANKLINE>
{normal} Ran {green}200{normal} tests with {boldred}3{normal} failures and {boldred}1{normal} errors in {green}0.045{normal} seconds.{normal}
{normal}Running samplelayers.Layer1 tests:{normal}
- Set up samplelayers.Layer1 in 0.000 seconds.
+ Set up samplelayers.Layer1 in {green}0.000{normal} seconds.
{normal} Ran {green}9{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.001{normal} seconds.{normal}
{normal}Running samplelayers.Layer11 tests:{normal}
- Set up samplelayers.Layer11 in 0.000 seconds.
+ Set up samplelayers.Layer11 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.007{normal} seconds.{normal}
{normal}Running samplelayers.Layer111 tests:{normal}
- Set up samplelayers.Layerx in 0.000 seconds.
- Set up samplelayers.Layer111 in 0.000 seconds.
+ Set up samplelayers.Layerx in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer111 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.008{normal} seconds.{normal}
{normal}Running samplelayers.Layer112 tests:{normal}
- Tear down samplelayers.Layer111 in 0.000 seconds.
- Set up samplelayers.Layer112 in 0.000 seconds.
+ Tear down samplelayers.Layer111 in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer112 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.008{normal} seconds.{normal}
{normal}Running samplelayers.Layer12 tests:{normal}
- Tear down samplelayers.Layer112 in 0.000 seconds.
- Tear down samplelayers.Layerx in 0.000 seconds.
- Tear down samplelayers.Layer11 in 0.000 seconds.
- Set up samplelayers.Layer12 in 0.000 seconds.
+ Tear down samplelayers.Layer112 in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layerx in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layer11 in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer12 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.007{normal} seconds.{normal}
{normal}Running samplelayers.Layer121 tests:{normal}
- Set up samplelayers.Layer121 in 0.000 seconds.
+ Set up samplelayers.Layer121 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.007{normal} seconds.{normal}
{normal}Running samplelayers.Layer122 tests:{normal}
- Tear down samplelayers.Layer121 in 0.000 seconds.
- Set up samplelayers.Layer122 in 0.000 seconds.
+ Tear down samplelayers.Layer121 in {green}0.000{normal} seconds.
+ Set up samplelayers.Layer122 in {green}0.000{normal} seconds.
{normal} Ran {green}34{normal} tests with {green}0{normal} failures and {green}0{normal} errors in {green}0.008{normal} seconds.{normal}
{normal}Tearing down left over layers:{normal}
- Tear down samplelayers.Layer122 in 0.000 seconds.
- Tear down samplelayers.Layer12 in 0.000 seconds.
- Tear down samplelayers.Layer1 in 0.000 seconds.
+ Tear down samplelayers.Layer122 in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layer12 in {green}0.000{normal} seconds.
+ Tear down samplelayers.Layer1 in {green}0.000{normal} seconds.
{normal}Total: {green}413{normal} tests, {boldred}3{normal} failures, {boldred}1{normal} errors in {green}0.023{normal} seconds.{normal}
True
Modified: zope.testing/trunk/src/zope/testing/testrunner.py
===================================================================
--- zope.testing/trunk/src/zope/testing/testrunner.py 2007-07-19 11:33:40 UTC (rev 78152)
+++ zope.testing/trunk/src/zope/testing/testrunner.py 2007-07-19 13:41:48 UTC (rev 78153)
@@ -376,15 +376,25 @@
for test in import_errors:
print " " + test.module
+ def format_seconds(self, n_seconds):
+ """Format a time in seconds."""
+ return "%.3f seconds" % n_seconds
+
+ def format_seconds_short(self, n_seconds):
+ """Format a time in seconds (short version)."""
+ return "%.3f s" % n_seconds
+
def summary(self, n_tests, n_failures, n_errors, n_seconds):
"""Summarize the results of a single test layer."""
- print (" Ran %s tests with %s failures and %s errors in %.3f seconds."
- % (n_tests, n_failures, n_errors, n_seconds))
+ print (" Ran %s tests with %s failures and %s errors in %s."
+ % (n_tests, n_failures, n_errors,
+ self.format_seconds(n_seconds)))
def totals(self, n_tests, n_failures, n_errors, n_seconds):
"""Summarize the results of all layers."""
- print "Total: %s tests, %s failures, %s errors in %.3f seconds." % (
- n_tests, n_failures, n_errors, n_seconds)
+ print ("Total: %s tests, %s failures, %s errors in %s."
+ % (n_tests, n_failures, n_errors,
+ self.format_seconds(n_seconds)))
def list_of_tests(self, tests, layer_name):
"""Report a list of test names."""
@@ -437,7 +447,7 @@
Should be called right after start_set_up().
"""
- print "in %.3f seconds." % seconds
+ print "in %s." % self.format_seconds(seconds)
def start_tear_down(self, layer_name):
"""Report that we're tearing down a layer.
@@ -453,7 +463,7 @@
Should be called right after start_tear_down().
"""
- print "in %.3f seconds." % seconds
+ print "in %s." % self.format_seconds(seconds)
def tear_down_not_supported(self):
"""Report that we could not tear down a layer.
@@ -502,7 +512,7 @@
The next output operation should be stop_test().
"""
if self.verbose > 2:
- s = " (%.3f s)" % seconds
+ s = " (%s)" % self.format_seconds_short(seconds)
sys.stdout.write(s)
self.test_width += len(s) + 1
@@ -514,7 +524,7 @@
The next output operation should be stop_test().
"""
if self.verbose > 2:
- print " (%.3f s)" % seconds
+ print " (%s)" % self.format_seconds_short(seconds)
print
self.print_traceback("Error in test %s" % test, exc_info)
self.test_width = self.last_width = 0
@@ -527,7 +537,7 @@
The next output operation should be stop_test().
"""
if self.verbose > 2:
- print " (%.3f s)" % seconds
+ print " (%s)" % self.format_seconds_short(seconds)
print
self.print_traceback("Failure in test %s" % test, exc_info)
self.test_width = self.last_width = 0
@@ -643,9 +653,9 @@
"""Pick a named color from the color scheme"""
return self.color_code(self.colorscheme[what])
- def colorize(self, what, message):
+ def colorize(self, what, message, normal='normal'):
"""Wrap message in color."""
- return self.color(what) + message + self.color_code('normal')
+ return self.color(what) + message + self.color(normal)
def error_count_color(self, n):
"""Choose a color for the number of errors."""
@@ -685,6 +695,10 @@
"""
print "...", self.colorize('suboptimal-behaviour', "not supported")
+ def format_seconds(self, n_seconds, normal='normal'):
+ """Format a time in seconds."""
+ return self.colorize('number', "%.3f" % n_seconds, normal) + ' seconds'
+
def summary(self, n_tests, n_failures, n_errors, n_seconds):
"""Summarize the results."""
sys.stdout.writelines([
@@ -695,8 +709,7 @@
self.color('info'), ' failures and ',
self.error_count_color(n_errors), str(n_errors),
self.color('info'), ' errors in ',
- self.color('number'), '%.3f' % n_seconds,
- self.color('info'), ' seconds.',
+ self.format_seconds(n_seconds, 'info'), '.',
self.color('normal'), '\n'])
def totals(self, n_tests, n_failures, n_errors, n_seconds):
@@ -709,8 +722,7 @@
self.color('info'), ' failures, ',
self.error_count_color(n_errors), str(n_errors),
self.color('info'), ' errors in ',
- self.color('number'), '%.3f' % n_seconds,
- self.color('info'), ' seconds.',
+ self.format_seconds(n_seconds, 'info'), '.',
self.color('normal'), '\n'])
def print_traceback(self, msg, exc_info):
More information about the Zope3-Checkins
mailing list