Add reporter PoC 03/29203/2
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Wed, 22 Feb 2017 08:57:48 +0000 (16:57 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Wed, 22 Feb 2017 09:04:47 +0000 (17:04 +0800)
Change-Id: I5134a0d95d75fcb3a75267a5f20b4ace8638156a
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
qtip/reporter/base.py [deleted file]
qtip/reporter/console.py [moved from qtip/reporter/console/__init__.py with 53% similarity]
qtip/reporter/templates/timeline.j2 [moved from qtip/reporter/console/timeline.j2 with 100% similarity]
tests/unit/reporter/console_test.py [new file with mode: 0644]

diff --git a/qtip/reporter/base.py b/qtip/reporter/base.py
deleted file mode 100644 (file)
index b931d14..0000000
+++ /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
similarity index 53%
rename from qtip/reporter/console/__init__.py
rename to qtip/reporter/console.py
index 02d6328..24c98e7 100644 (file)
@@ -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/tests/unit/reporter/console_test.py b/tests/unit/reporter/console_test.py
new file mode 100644 (file)
index 0000000..8150239
--- /dev/null
@@ -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'