Merge pull request #95 from Mirantis/cgenie/better-test-results
Better display of 'solar changes test' results
This commit is contained in:
commit
76d684719d
@ -75,7 +75,23 @@ def history(n):
|
||||
|
||||
@changes.command()
|
||||
def test():
|
||||
testing.test_all()
|
||||
results = testing.test_all()
|
||||
|
||||
for name, result in results.items():
|
||||
msg = '[{status}] {name} {message}'
|
||||
kwargs = {
|
||||
'name': name,
|
||||
'message': '',
|
||||
'status': 'OK',
|
||||
}
|
||||
|
||||
if result['status'] == 'ok':
|
||||
kwargs['status'] = click.style('OK', fg='green')
|
||||
else:
|
||||
kwargs['status'] = click.style('ERROR', fg='red')
|
||||
kwargs['message'] = result['message']
|
||||
|
||||
click.echo(msg.format(**kwargs))
|
||||
|
||||
|
||||
@changes.command(name='clean-history')
|
||||
|
@ -1,25 +1,28 @@
|
||||
import imp
|
||||
import networkx as nx
|
||||
import os
|
||||
import traceback
|
||||
|
||||
from log import log
|
||||
from solar.core import resource
|
||||
from solar.core import signals
|
||||
|
||||
|
||||
def test_all():
|
||||
results = {}
|
||||
|
||||
conn_graph = signals.detailed_connection_graph()
|
||||
#srt = nx.topological_sort(conn_graph)
|
||||
|
||||
for name in conn_graph:
|
||||
print 'Trying {}'.format(name)
|
||||
log.debug('Trying {}'.format(name))
|
||||
r = resource.load(name)
|
||||
|
||||
script_path = os.path.join(r.metadata['base_path'], 'test.py')
|
||||
if not os.path.exists(script_path):
|
||||
print 'WARNING: resource {} has no tests'.format(name)
|
||||
log.warning('resource {} has no tests'.format(name))
|
||||
continue
|
||||
|
||||
print 'File {} found'.format(script_path)
|
||||
log.debug('File {} found'.format(script_path))
|
||||
|
||||
with open(script_path) as f:
|
||||
module = imp.load_module(
|
||||
@ -29,4 +32,15 @@ def test_all():
|
||||
('', 'r', imp.PY_SOURCE)
|
||||
)
|
||||
|
||||
module.test(r)
|
||||
try:
|
||||
module.test(r)
|
||||
results[name] = {
|
||||
'status': 'ok',
|
||||
}
|
||||
except Exception:
|
||||
results[name] = {
|
||||
'status': 'error',
|
||||
'message': traceback.format_exc(),
|
||||
}
|
||||
|
||||
return results
|
||||
|
Loading…
x
Reference in New Issue
Block a user