Commit d8e3b6c5 authored by Jason Madden's avatar Jason Madden

Colorize testrunner output.

parent 3056db5f
......@@ -150,7 +150,7 @@ def run_many(tests, configured_failing_tests=(), failfast=False, quiet=False):
try:
try:
log("Running tests in parallel with concurrency %s" % (NWORKERS,))
log("Running tests in parallel with concurrency %s" % (NWORKERS,),)
for cmd, options in tests:
total += 1
options = options or {}
......@@ -297,7 +297,7 @@ def report(total, failed, passed, exit=True, took=None,
passed_unexpected.append(name)
if passed_unexpected:
log('\n%s/%s unexpected passes', len(passed_unexpected), total)
log('\n%s/%s unexpected passes', len(passed_unexpected), total, color='error')
print_list(passed_unexpected)
if failed:
......@@ -314,7 +314,7 @@ def report(total, failed, passed, exit=True, took=None,
print_list(failed_expected)
if failed_unexpected:
log('\n%s/%s unexpected failures', len(failed_unexpected), total)
log('\n%s/%s unexpected failures', len(failed_unexpected), total, color='error')
print_list(failed_unexpected)
else:
log('\n%s tests passed%s', total, took)
......
......@@ -24,7 +24,70 @@ class Popen(subprocess.Popen):
kill(self)
def log(message, *args):
# Coloring code based on zope.testrunner
# These colors are carefully chosen to have enough contrast
# on terminals with both black and white background.
_colorscheme = {
'normal': 'normal',
'default': 'default',
'info': 'normal',
'suboptimal-behaviour': 'magenta',
'error': 'brightred',
'number': 'green',
'slow-test': 'brightmagenta',
'ok-number': 'green',
'error-number': 'brightred',
'filename': 'lightblue',
'lineno': 'lightred',
'testname': 'lightcyan',
'failed-example': 'cyan',
'expected-output': 'green',
'actual-output': 'red',
'character-diffs': 'magenta',
'diff-chunk': 'magenta',
'exception': 'red',
'skipped': 'brightyellow',
}
_prefixes = [
('dark', '0;'),
('light', '1;'),
('bright', '1;'),
('bold', '1;'),
]
_colorcodes = {
'default': 0,
'normal': 0,
'black': 30,
'red': 31,
'green': 32,
'brown': 33, 'yellow': 33,
'blue': 34,
'magenta': 35,
'cyan': 36,
'grey': 37, 'gray': 37, 'white': 37
}
def _color_code(color):
prefix_code = ''
for prefix, code in _prefixes:
if color.startswith(prefix):
color = color[len(prefix):]
prefix_code = code
break
color_code = _colorcodes[color]
return '\033[%s%sm' % (prefix_code, color_code)
def _color(what):
return _color_code(_colorscheme[what])
def _colorize(what, message, normal='normal'):
return _color(what) + message + _color(normal)
def log(message, *args, **kwargs):
color = kwargs.pop('color', 'normal')
try:
if args:
string = message % args
......@@ -37,10 +100,12 @@ def log(message, *args):
except Exception:
pass
try:
string = _colorize('exception', string)
sys.stderr.write(string)
except Exception:
traceback.print_exc()
else:
string = _colorize(color, string)
sys.stderr.write(string + '\n')
......@@ -225,7 +290,7 @@ def run(command, **kwargs):
out += '\n'
log('| %s\n%s', name, out)
if result:
log('! %s [code %s] [took %.1fs]', name, result, took)
log('! %s [code %s] [took %.1fs]', name, result, took, color='error')
elif not nested:
log('- %s [took %.1fs]', name, took)
if took >= MIN_RUNTIME:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment