提交 2e6ecce6 编写于 作者: C Cleber Rosa 提交者: Lukáš Doktor

Result: make human UI a ResultEvents plugin

Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 74ea1680
......@@ -285,10 +285,6 @@ class Job(object):
test_result_instance = klass(self)
self.result_proxy.add_output_plugin(test_result_instance)
if not getattr(self.args, 'stdout_claimed_by', False) or self.standalone:
human_plugin = result.HumanResult(self)
self.result_proxy.add_output_plugin(human_plugin)
if not self.result_proxy.output_plugins:
self.result_proxy.add_output_plugin(result.Result(self))
......
......@@ -15,15 +15,8 @@
"""
Contains the definition of the Result class, used for output in avocado.
It also contains the most basic result class, HumanResult, used by the
test runner.
"""
import logging
from . import output
class InvalidOutputPlugin(Exception):
pass
......@@ -180,75 +173,3 @@ class Result(object):
else:
self.errors += 1
self.end_test(state)
class HumanResult(Result):
"""
Human output Test result class.
"""
def __init__(self, job):
super(HumanResult, self).__init__(job)
self.log = logging.getLogger("avocado.app")
self.__throbber = output.Throbber()
self._replay_source_job = getattr(job.args, "replay_sourcejob", None)
def start_tests(self):
"""
Called once before any tests are executed.
"""
super(HumanResult, self).start_tests()
self.log.info("JOB ID : %s", self.job_unique_id)
if self._replay_source_job is not None:
self.log.info("SRC JOB ID : %s", self._replay_source_job)
self.log.info("JOB LOG : %s", self.logfile)
self.log.info("TESTS : %s", self.tests_total)
def end_tests(self):
"""
Called once after all tests are executed.
"""
super(HumanResult, self).end_tests()
self.log.info("RESULTS : PASS %d | ERROR %d | FAIL %d | SKIP %d | "
"WARN %d | INTERRUPT %s", self.passed,
self.errors, self.failed, self.skipped,
self.warned, self.interrupted)
self.log.info("TESTS TIME : %.2f s", self.tests_total_time)
def start_test(self, state):
super(HumanResult, self).start_test(state)
if "name" in state:
name = state["name"]
uid = name.str_uid
name = name.name + name.str_variant
else:
name = "<unknown>"
uid = '?'
self.log.debug(' (%s/%s) %s: ', uid, self.tests_total, name,
extra={"skip_newline": True})
def end_test(self, state):
super(HumanResult, self).end_test(state)
status = state.get("status", "ERROR")
if status == "TEST_NA":
status = "SKIP"
mapping = {'PASS': output.TERM_SUPPORT.PASS,
'ERROR': output.TERM_SUPPORT.ERROR,
'FAIL': output.TERM_SUPPORT.FAIL,
'SKIP': output.TERM_SUPPORT.SKIP,
'WARN': output.TERM_SUPPORT.WARN,
'INTERRUPTED': output.TERM_SUPPORT.INTERRUPT}
duration = (" (%.2f s)" % state.get('time_elapsed', -1)
if status != "SKIP"
else "")
self.log.debug(output.TERM_SUPPORT.MOVE_BACK + mapping[status] +
status + output.TERM_SUPPORT.ENDC + duration)
def notify_progress(self, progress=False):
if progress:
color = output.TERM_SUPPORT.PASS
else:
color = output.TERM_SUPPORT.PARTIAL
self.log.debug(color + self.__throbber.render() +
output.TERM_SUPPORT.ENDC, extra={"skip_newline": True})
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See LICENSE for more details.
#
# Copyright: Red Hat, Inc. 2016
# Author: Cleber Rosa <crosa@redhat.com>
"""
Human result UI
"""
import logging
from avocado.core.plugin_interfaces import ResultEvents
from avocado.core import output
class Human(ResultEvents):
"""
Human result UI
"""
name = 'human'
description = "Human Interface UI"
output_mapping = {'PASS': output.TERM_SUPPORT.PASS,
'ERROR': output.TERM_SUPPORT.ERROR,
'FAIL': output.TERM_SUPPORT.FAIL,
'SKIP': output.TERM_SUPPORT.SKIP,
'WARN': output.TERM_SUPPORT.WARN,
'INTERRUPTED': output.TERM_SUPPORT.INTERRUPT}
def __init__(self, args):
self.log = logging.getLogger("avocado.app")
self.__throbber = output.Throbber()
stdout_claimed_by = getattr(args, 'stdout_claimed_by', None)
self.owns_stdout = not stdout_claimed_by
def pre_tests(self, job):
if not self.owns_stdout:
return
self.log.info("JOB ID : %s", job.unique_id)
replay_source_job = getattr(job.args, "replay_sourcejob", False)
if replay_source_job:
self.log.info("SRC JOB ID : %s", self.__replay_source_job)
self.log.info("JOB LOG : %s", job.logfile)
self.log.info("TESTS : %s", len(job.test_suite))
def start_test(self, result, state):
if not self.owns_stdout:
return
if "name" in state:
name = state["name"]
uid = name.str_uid
name = name.name + name.str_variant
else:
name = "<unknown>"
uid = '?'
self.log.debug(' (%s/%s) %s: ', uid, result.tests_total, name,
extra={"skip_newline": True})
def test_progress(self, progress=False):
if not self.owns_stdout:
return
if progress:
color = output.TERM_SUPPORT.PASS
else:
color = output.TERM_SUPPORT.PARTIAL
self.log.debug(color + self.__throbber.render() +
output.TERM_SUPPORT.ENDC, extra={"skip_newline": True})
def end_test(self, result, state):
if not self.owns_stdout:
return
status = state.get("status", "ERROR")
if status == "TEST_NA":
status = "SKIP"
duration = (" (%.2f s)" % state.get('time_elapsed', -1)
if status != "SKIP"
else "")
self.log.debug(output.TERM_SUPPORT.MOVE_BACK +
self.output_mapping[status] +
status + output.TERM_SUPPORT.ENDC +
duration)
def post_tests(self, job):
if not self.owns_stdout:
return
self.log.info("RESULTS : PASS %d | ERROR %d | FAIL %d | SKIP %d | "
"WARN %d | INTERRUPT %s", job.result.passed,
job.result.errors, job.result.failed, job.result.skipped,
job.result.warned, job.result.interrupted)
self.log.info("TESTS TIME : %.2f s", job.result.tests_total_time)
......@@ -160,6 +160,9 @@ if __name__ == '__main__':
'json = avocado.plugins.jsonresult:JSONResult',
'zip_archive = avocado.plugins.archive:Archive',
],
'avocado.plugins.result_events': [
'human = avocado.plugins.human:Human',
],
},
zip_safe=False,
test_suite='selftests',
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册