From 2e6ecce6852978f63e9c38ce16d4569b6e200c83 Mon Sep 17 00:00:00 2001 From: Cleber Rosa Date: Fri, 4 Nov 2016 15:42:07 +0100 Subject: [PATCH] Result: make human UI a ResultEvents plugin Signed-off-by: Cleber Rosa --- avocado/core/job.py | 4 -- avocado/core/result.py | 79 ------------------------------- avocado/plugins/human.py | 100 +++++++++++++++++++++++++++++++++++++++ setup.py | 3 ++ 4 files changed, 103 insertions(+), 83 deletions(-) create mode 100644 avocado/plugins/human.py diff --git a/avocado/core/job.py b/avocado/core/job.py index 81c630d3..e283d982 100644 --- a/avocado/core/job.py +++ b/avocado/core/job.py @@ -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)) diff --git a/avocado/core/result.py b/avocado/core/result.py index 03c838c9..2bcbe051 100644 --- a/avocado/core/result.py +++ b/avocado/core/result.py @@ -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 = "" - 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}) diff --git a/avocado/plugins/human.py b/avocado/plugins/human.py new file mode 100644 index 00000000..5aaca7a6 --- /dev/null +++ b/avocado/plugins/human.py @@ -0,0 +1,100 @@ +# 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 +""" +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 = "" + 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) diff --git a/setup.py b/setup.py index 481dfd30..763f8566 100755 --- a/setup.py +++ b/setup.py @@ -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', -- GitLab