From 249005cfed9ff95de0d97d3afdc165bbe1af3a88 Mon Sep 17 00:00:00 2001 From: Lucas Meneghel Rodrigues Date: Tue, 10 Jun 2014 04:49:51 -0300 Subject: [PATCH] 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: Lucas Meneghel Rodrigues --- avocado/result.py | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/avocado/result.py b/avocado/result.py index 072a3da3..014b2e1b 100644 --- a/avocado/result.py +++ b/avocado/result.py @@ -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): """ -- GitLab