Implement TestPlan prototype 15/25515/2
authorYujun Zhang <zhang.yujunz@zte.com.cn>
Tue, 6 Dec 2016 08:30:11 +0000 (16:30 +0800)
committerYujun Zhang <zhang.yujunz@zte.com.cn>
Tue, 6 Dec 2016 08:46:18 +0000 (16:46 +0800)
Refactor common part of Suite to Benchmark since both TestPlan
and Suite are organized by files

Change-Id: I61a97d9489096c4a6305c99e8cf7abb958faa562
Signed-off-by: Yujun Zhang <zhang.yujunz@zte.com.cn>
qtip/runner/benchmark.py [new file with mode: 0644]
qtip/runner/suite.py
qtip/runner/testplan.py
tests/unit/runner/suite_test.py
tests/unit/runner/test_plan_test.py [deleted file]
tests/unit/runner/testplan_test.py [new file with mode: 0644]

diff --git a/qtip/runner/benchmark.py b/qtip/runner/benchmark.py
new file mode 100644 (file)
index 0000000..46cb069
--- /dev/null
@@ -0,0 +1,56 @@
+##############################################################################
+# 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 itertools import chain
+from os import listdir
+from os import path
+
+
+class Property:
+    NAME = 'name'
+    DESCRIPTION = 'description'
+    ABSPATH = 'abspath'
+
+
+class Benchmark:
+    """Abstract class of QTIP benchmarks"""
+
+    # paths to search for suites
+    _paths = [path.join(path.dirname(__file__), path.pardir, path.pardir,
+                        'benchmarks')]
+
+    def __init__(self, name):
+        """:param name: suite name"""
+        # TODO(yujunz) check existence and expand to full path
+        self.name = name
+        self._abspath = self._find(name)
+
+    def _find(self, name):
+        """find a benchmark in searching paths"""
+        for p in self._paths:
+            abspath = path.join(p, name)
+            if path.exists(abspath):
+                return abspath
+        return None
+
+    @classmethod
+    def list_all(cls):
+        """list all available benchmarks"""
+        names = chain.from_iterable([listdir(p) for p in cls._paths])
+        return [Benchmark(name).describe() for name in names]
+
+    def describe(self):
+        """description of benchmark"""
+        # TODO(yujunz)
+        # - read description from benchmark content
+        return {
+            Property.NAME: self.name,
+            Property.DESCRIPTION: 'QTIP benchmark',
+            Property.ABSPATH: self._abspath
+        }
index 1892bb2..4179af6 100644 (file)
@@ -7,58 +7,13 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-from itertools import chain
-from os import listdir
 from os import path
 
+from benchmark import Benchmark
 
-class SuiteProperty:
-    NAME = 'name'
-    DESCRIPTION = 'description'
-    ABSPATH = 'abspath'
 
-
-class Suite:
+class Suite(Benchmark):
     """A suite is consist of one or several perf tests and produces one QPI"""
 
     # paths to search for suites
-    _paths = [path.join(path.dirname(__file__), path.pardir, path.pardir,
-                        'benchmarks', 'suite')]
-
-    def __init__(self, name):
-        """:param name: suite name"""
-        # TODO(yujunz) check existence and expand to full path
-        self.name = name
-        self._abspath = self._find(name)
-
-    def _find(self, name):
-        """find a suite in searching paths"""
-        for p in self._paths:
-            abspath = path.join(p, name)
-            if path.exists(abspath):
-                return abspath
-        return None
-
-    @classmethod
-    def list_all(cls):
-        """list all available suites"""
-        suite_names = chain.from_iterable([listdir(p) for p in cls._paths])
-        return [Suite(name).describe() for name in suite_names]
-
-    def describe(self):
-        """description of benchmark suite"""
-        # TODO(yujunz)
-        # - read description from suite content
-        # - verbose mode including even more details
-        #   - referred perftests
-        #   - formula of QPI calculation
-        #   - baseline description
-        return {
-            SuiteProperty.NAME: self.name,
-            SuiteProperty.DESCRIPTION: 'QTIP benchmark suite',
-            SuiteProperty.ABSPATH: self._abspath
-        }
-
-    def run(self):
-        """run included perftests in the suite"""
-        pass
+    _paths = [path.join(p, 'suite') for p in Benchmark._paths]
index d20221d..57f3c97 100644 (file)
@@ -7,22 +7,13 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
+from os import path
 
-class TestPlan:
-    """A test plan is consist of test configuration and selected test suites"""
+from benchmark import Benchmark
 
-    def __init__(self):
-        pass
 
-    @staticmethod
-    def list_all():
-        """list all available test plans"""
-        pass
+class TestPlan(Benchmark):
+    """A suite is consist of one or several perf tests and produces one QPI"""
 
-    def desc(self):
-        """description of the test plan"""
-        pass
-
-    def run(self):
-        """run included suites"""
-        pass
+    # paths to search for suites
+    _paths = [path.join(p, 'testplan') for p in Benchmark._paths]
index 0539cee..5d2f106 100644 (file)
@@ -11,7 +11,7 @@ from os import path
 import pytest
 
 from qtip.runner.suite import Suite
-from qtip.runner.suite import SuiteProperty as SProp
+from qtip.runner.benchmark import Property
 
 
 class TestSuiteClass:
@@ -36,6 +36,6 @@ class TestSuite:
         suite_list = Suite.list_all()
         assert len(list(suite_list)) is 3
         for suite_desc in suite_list:
-            assert SProp.NAME in suite_desc
-            assert SProp.DESCRIPTION in suite_desc
-            assert SProp.ABSPATH in suite_desc
+            assert Property.NAME in suite_desc
+            assert Property.DESCRIPTION in suite_desc
+            assert Property.ABSPATH in suite_desc
diff --git a/tests/unit/runner/test_plan_test.py b/tests/unit/runner/test_plan_test.py
deleted file mode 100644 (file)
index 81f618c..0000000
+++ /dev/null
@@ -1,13 +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 TestTestPlan:
-    def test_list(self):
-        assert True
diff --git a/tests/unit/runner/testplan_test.py b/tests/unit/runner/testplan_test.py
new file mode 100644 (file)
index 0000000..2700d38
--- /dev/null
@@ -0,0 +1,41 @@
+##############################################################################
+# 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 os import path
+import pytest
+
+from qtip.runner.testplan import TestPlan
+from qtip.runner.benchmark import Property
+
+
+class TestTestPlanClass:
+    def test_attr(self):
+        assert len(TestPlan._paths) is 1
+
+
+class TestTestPlan:
+    TestPlan._paths = [path.join(path.dirname(__file__), path.pardir,
+                                 path.pardir, 'data', 'testplan')]
+
+    def test_init(self):
+        plan = TestPlan('plan-a')
+        assert plan.name == 'plan-a'
+
+        with pytest.raises(TypeError) as excinfo:
+            TestPlan()
+        assert '__init__() takes exactly 2 arguments (1 given)' \
+               in str(excinfo.value)
+
+    def test_list(self):
+        plan_list = TestPlan.list_all()
+        assert len(list(plan_list)) is 5
+        for desc in plan_list:
+            assert Property.NAME in desc
+            assert Property.DESCRIPTION in desc
+            assert Property.ABSPATH in desc