From 4727d91cae2e71f6ae0751f4d6e6559d5221b0f2 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Wed, 22 Feb 2017 16:57:48 +0800 Subject: [PATCH] Add reporter PoC Change-Id: I5134a0d95d75fcb3a75267a5f20b4ace8638156a Signed-off-by: Yujun Zhang --- qtip/reporter/base.py | 14 ----------- qtip/reporter/{console/__init__.py => console.py} | 14 ++++++++--- qtip/reporter/{console => templates}/timeline.j2 | 0 tests/unit/reporter/console_test.py | 29 +++++++++++++++++++++++ 4 files changed, 40 insertions(+), 17 deletions(-) delete mode 100644 qtip/reporter/base.py rename qtip/reporter/{console/__init__.py => console.py} (53%) rename qtip/reporter/{console => templates}/timeline.j2 (100%) create mode 100644 tests/unit/reporter/console_test.py diff --git a/qtip/reporter/base.py b/qtip/reporter/base.py deleted file mode 100644 index b931d14d..00000000 --- a/qtip/reporter/base.py +++ /dev/null @@ -1,14 +0,0 @@ -############################################################################## -# Copyright (c) 2016 ZTE Corp and others. -# -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Apache License, Version 2.0 -# which accompanies this distribution, and is available at -# http://www.apache.org/licenses/LICENSE-2.0 -############################################################################## - - -class BaseReporter(object): - """benchmark result reporter""" - def __init__(self, collector=None): - self.collector = collector diff --git a/qtip/reporter/console/__init__.py b/qtip/reporter/console.py similarity index 53% rename from qtip/reporter/console/__init__.py rename to qtip/reporter/console.py index 02d63288..24c98e74 100644 --- a/qtip/reporter/console/__init__.py +++ b/qtip/reporter/console.py @@ -7,9 +7,17 @@ # http://www.apache.org/licenses/LICENSE-2.0 ############################################################################## +from qtip.base import BaseActor -from qtip.reporter.base import BaseReporter +class ConsoleReporter(BaseActor): + """ + report benchmark result to console + """ + def __init__(self, config, parent=None): + super(ConsoleReporter, self).__init__(config, parent=parent) + # TODO(yujunz) remove PoC code + self._fmt = "{title}: {description}" -class ConsoleReporter(BaseReporter): - """report result to console""" + def render(self, var_dict): + return self._fmt.format(**var_dict) diff --git a/qtip/reporter/console/timeline.j2 b/qtip/reporter/templates/timeline.j2 similarity index 100% rename from qtip/reporter/console/timeline.j2 rename to qtip/reporter/templates/timeline.j2 diff --git a/tests/unit/reporter/console_test.py b/tests/unit/reporter/console_test.py new file mode 100644 index 00000000..8150239e --- /dev/null +++ b/tests/unit/reporter/console_test.py @@ -0,0 +1,29 @@ +############################################################################## +# Copyright (c) 2017 ZTE Corporation and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## + +import pytest +from qtip.reporter.console import ConsoleReporter + + +@pytest.fixture +def console_reporter(): + return ConsoleReporter({}) + + +def test_constructor(console_reporter): + assert isinstance(console_reporter, ConsoleReporter) + + +def test_render(console_reporter): + var_dict = { + 'title': 'fake title', + 'description': 'fake description' + } + output = console_reporter.render(var_dict=var_dict) + assert output == 'fake title: fake description' -- 2.16.6