From 95092b511dbacac412dbe5b8ff3a28abb3d3f664 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Fri, 10 Aug 2018 12:55:10 +0200 Subject: Leverage on abc and stevedore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I7b3c4c0c5dd0c9e6fb3e52c3fff5221d4b831b02 Signed-off-by: Cédric Ollivier --- xtesting/tests/unit/core/test_feature.py | 15 ++++++++++++- xtesting/tests/unit/core/test_testcase.py | 35 ++++++++++++++++++++----------- 2 files changed, 37 insertions(+), 13 deletions(-) (limited to 'xtesting/tests/unit/core') diff --git a/xtesting/tests/unit/core/test_feature.py b/xtesting/tests/unit/core/test_feature.py index 72bc488f..a4ac5af7 100644 --- a/xtesting/tests/unit/core/test_feature.py +++ b/xtesting/tests/unit/core/test_feature.py @@ -18,6 +18,19 @@ from xtesting.core import feature from xtesting.core import testcase +class FakeTestCase(feature.Feature): + + def execute(self, **kwargs): + pass + + +class AbstractFeatureTesting(unittest.TestCase): + + def test_run_unimplemented(self): + with self.assertRaises(TypeError): + feature.Feature(case_name="feature", project_name="xtesting") + + class FeatureTestingBase(unittest.TestCase): _case_name = "foo" @@ -46,7 +59,7 @@ class FeatureTesting(FeatureTestingBase): # what will break these unit tests. logging.disable(logging.CRITICAL) with mock.patch('six.moves.builtins.open'): - self.feature = feature.Feature( + self.feature = FakeTestCase( project_name=self._project_name, case_name=self._case_name) def test_run_exc(self): diff --git a/xtesting/tests/unit/core/test_testcase.py b/xtesting/tests/unit/core/test_testcase.py index 6b83b97c..51ea6f35 100644 --- a/xtesting/tests/unit/core/test_testcase.py +++ b/xtesting/tests/unit/core/test_testcase.py @@ -7,6 +7,8 @@ # which accompanies this distribution, and is available at # http://www.apache.org/licenses/LICENSE-2.0 +# pylint: disable=missing-docstring + """Define the class required to fully cover testcase.""" from datetime import datetime @@ -23,10 +25,22 @@ from xtesting.core import testcase __author__ = "Cedric Ollivier " -class TestCaseTesting(unittest.TestCase): - """The class testing TestCase.""" +class FakeTestCase(testcase.TestCase): + # pylint: disable=too-many-instance-attributes + + def run(self, **kwargs): + return testcase.TestCase.EX_OK + + +class AbstractTestCaseTesting(unittest.TestCase): + + def test_run_unimplemented(self): + with self.assertRaises(TypeError): + testcase.TestCase(case_name="base", project_name="xtesting") - # pylint: disable=missing-docstring,too-many-public-methods + +class TestCaseTesting(unittest.TestCase): + # pylint: disable=too-many-instance-attributes,too-many-public-methods _case_name = "base" _project_name = "xtesting" @@ -35,8 +49,8 @@ class TestCaseTesting(unittest.TestCase): _headers = {'Content-Type': 'application/json'} def setUp(self): - self.test = testcase.TestCase(case_name=self._case_name, - project_name=self._project_name) + self.test = FakeTestCase( + case_name=self._case_name, project_name=self._project_name) self.test.start_time = 1 self.test.stop_time = 2 self.test.result = 100 @@ -47,9 +61,8 @@ class TestCaseTesting(unittest.TestCase): os.environ['NODE_NAME'] = "node_name" os.environ['BUILD_TAG'] = "foo-daily-master-bar" - def test_run_unimplemented(self): - self.assertEqual(self.test.run(), - testcase.TestCase.EX_RUN_ERROR) + def test_run_fake(self): + self.assertEqual(self.test.run(), testcase.TestCase.EX_OK) def _test_pushdb_missing_attribute(self): self.assertEqual(self.test.push_to_db(), @@ -255,13 +268,11 @@ class TestCaseTesting(unittest.TestCase): def test_str_project_name_ko(self): self.test.project_name = None - self.assertIn("