avocado.result: Introduce TestResultProxy

Create a class that has the same interface as a
test result, but in fact has a list of test result
objects and can write to each of them any time
a test result operation is called. This is the
first step to make multiple output plugins to
work.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 519a1b48
......@@ -21,6 +21,70 @@ used by the test runner.
"""
class InvalidOutputPlugin(Exception):
pass
class TestResultProxy(object):
def __init__(self):
self.output_plugins = []
self.console_plugin = None
def __getattr__(self, attr):
for output_plugin in self.output_plugins:
if hasattr(output_plugin, attr):
return getattr(output_plugin, attr)
else:
return None
def add_output_plugin(self, plugin):
if not isinstance(plugin, TestResult):
raise InvalidOutputPlugin("Object %s is not an instance of "
"TestResult" % plugin)
self.output_plugins.append(plugin)
def start_tests(self):
for output_plugin in self.output_plugins:
output_plugin.start_tests()
def end_tests(self):
for output_plugin in self.output_plugins:
output_plugin.end_tests()
def start_test(self, test):
for output_plugin in self.output_plugins:
output_plugin.start_test(test)
def end_test(self, test):
for output_plugin in self.output_plugins:
output_plugin.end_test(test)
def add_pass(self, test):
for output_plugin in self.output_plugins:
output_plugin.add_pass(test)
def add_error(self, test):
for output_plugin in self.output_plugins:
output_plugin.add_error(test)
def add_fail(self, test):
for output_plugin in self.output_plugins:
output_plugin.add_fail(test)
def add_skip(self, test):
for output_plugin in self.output_plugins:
output_plugin.add_skip(test)
def add_warn(self, test):
for output_plugin in self.output_plugins:
output_plugin.add_warn(test)
def check_test(self, test):
for output_plugin in self.output_plugins:
output_plugin.check_test(test)
class TestResult(object):
"""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册