avocado: Make it possible to use multiple output plugins

Set up the TestResultProxy for the Job object, and
populate the test result objects according to what
the currently active plugins set. This means we go
on finding arguments with the suffix _result and
selecting any values that are classes derived from
TestResult and appending them to the result proxy.

With this, we can use any number of test result
plugins we'd like. If no test result objects are
set by plugins, fall back to the human output plugin.
Signed-off-by: NLucas Meneghel Rodrigues <lmr@redhat.com>
上级 249005cf
......@@ -178,27 +178,32 @@ class Job(object):
self.test_dir = data_dir.get_test_dir()
self.test_index = 1
self.status = "RUNNING"
self.result_proxy = result.TestResultProxy()
self.output_manager = output.OutputManager()
def _make_test_runner(self, test_result):
def _make_test_runner(self):
if hasattr(self.args, 'test_runner'):
test_runner_class = self.args.test_runner
else:
test_runner_class = TestRunner
test_runner = test_runner_class(job=self,
test_result=test_result)
return test_runner
def _make_test_result(self, urls):
if hasattr(self.args, 'test_result'):
test_result_class = self.args.test_result
else:
test_result_class = result.HumanTestResult
if self.args is not None:
self.args.test_result_total = len(urls)
test_result = test_result_class(self.output_manager, self.args)
return test_result
self.test_runner = test_runner_class(job=self,
test_result=self.result_proxy)
def _make_test_result(self):
if self.args:
for key in self.args.__dict__:
if key.endswith('_result'):
result_class = getattr(self.args, key)
if issubclass(result_class, result.TestResult):
result_plugin = result_class(self.output_manager,
self.args)
self.result_proxy.add_output_plugin(result_plugin)
if not self.result_proxy.output_plugins:
default_plugin = result.HumanTestResult(self.output_manager, self.args)
self.result_proxy.add_output_plugin(default_plugin)
def _run(self, urls=None, multiplex_file=None):
"""
......@@ -248,8 +253,11 @@ class Job(object):
for dct in parser.get_dicts():
params_list.append(dct)
test_result = self._make_test_result(params_list)
self.test_runner = self._make_test_runner(test_result)
if self.args is not None:
self.args.test_result_total = len(params_list)
self._make_test_result()
self._make_test_runner()
self.output_manager.start_file_logging(self.debuglog,
self.loglevel)
......
......@@ -121,4 +121,4 @@ class Journal(plugin.Plugin):
def activate(self, app_args):
if app_args.journal:
self.parser.set_defaults(test_result=TestResultJournal)
self.parser.set_defaults(journal_result=TestResultJournal)
......@@ -94,4 +94,4 @@ class JSON(plugin.Plugin):
def activate(self, app_args):
if app_args.json:
self.parser.set_defaults(test_result=JSONTestResult)
self.parser.set_defaults(json_result=JSONTestResult)
......@@ -120,6 +120,7 @@ class VMTestResult(TestResult):
self.vm.remote.send_files(test_path, self.remote_test_dir)
def setup(self):
self.urls = self.args.url.split()
if self.args.vm_domain is None:
e_msg = ('Please set Virtual Machine Domain with option '
'--vm-domain.')
......@@ -289,5 +290,5 @@ class RunVM(plugin.Plugin):
def activate(self, app_args):
if app_args.vm:
self.parser.set_defaults(test_result=VMTestResult,
self.parser.set_defaults(vm_result=VMTestResult,
test_runner=VMTestRunner)
......@@ -222,4 +222,4 @@ class XUnit(plugin.Plugin):
def activate(self, app_args):
if app_args.xunit:
self.parser.set_defaults(test_result=xUnitTestResult)
self.parser.set_defaults(xunit_result=xUnitTestResult)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册