From 4727d91cae2e71f6ae0751f4d6e6559d5221b0f2 Mon Sep 17 00:00:00 2001 From: Yujun Zhang Date: Wed, 22 Feb 2017 16:57:48 +0800 Subject: Add reporter PoC Change-Id: I5134a0d95d75fcb3a75267a5f20b4ace8638156a Signed-off-by: Yujun Zhang --- qtip/reporter/base.py | 14 -------------- qtip/reporter/console.py | 23 +++++++++++++++++++++++ qtip/reporter/console/__init__.py | 15 --------------- qtip/reporter/console/timeline.j2 | 8 -------- qtip/reporter/templates/timeline.j2 | 8 ++++++++ tests/unit/reporter/console_test.py | 29 +++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 37 deletions(-) delete mode 100644 qtip/reporter/base.py create mode 100644 qtip/reporter/console.py delete mode 100644 qtip/reporter/console/__init__.py delete mode 100644 qtip/reporter/console/timeline.j2 create mode 100644 qtip/reporter/templates/timeline.j2 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.py b/qtip/reporter/console.py new file mode 100644 index 00000000..24c98e74 --- /dev/null +++ b/qtip/reporter/console.py @@ -0,0 +1,23 @@ +############################################################################## +# 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 +############################################################################## + +from qtip.base import BaseActor + + +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}" + + def render(self, var_dict): + return self._fmt.format(**var_dict) diff --git a/qtip/reporter/console/__init__.py b/qtip/reporter/console/__init__.py deleted file mode 100644 index 02d63288..00000000 --- a/qtip/reporter/console/__init__.py +++ /dev/null @@ -1,15 +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 -############################################################################## - - -from qtip.reporter.base import BaseReporter - - -class ConsoleReporter(BaseReporter): - """report result to console""" diff --git a/qtip/reporter/console/timeline.j2 b/qtip/reporter/console/timeline.j2 deleted file mode 100644 index 9c18a996..00000000 --- a/qtip/reporter/console/timeline.j2 +++ /dev/null @@ -1,8 +0,0 @@ -{% title %} -{% for phase in phases %} -{{ phase.name|upper }}{{ "TIME" }} -{% for cp in phase.checkpoints %} -{{ cp.name }}{{ cp.timestamp}} -{% endfor %} -{% endfor %} -Total: {{ total }} diff --git a/qtip/reporter/templates/timeline.j2 b/qtip/reporter/templates/timeline.j2 new file mode 100644 index 00000000..9c18a996 --- /dev/null +++ b/qtip/reporter/templates/timeline.j2 @@ -0,0 +1,8 @@ +{% title %} +{% for phase in phases %} +{{ phase.name|upper }}{{ "TIME" }} +{% for cp in phase.checkpoints %} +{{ cp.name }}{{ cp.timestamp}} +{% endfor %} +{% endfor %} +Total: {{ total }} 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' -- cgit 1.2.3-korg