diff options
Diffstat (limited to 'functest/tests/unit/core')
-rw-r--r-- | functest/tests/unit/core/test_feature.py | 7 | ||||
-rw-r--r-- | functest/tests/unit/core/test_pytest_suite_runner.py | 51 | ||||
-rw-r--r-- | functest/tests/unit/core/test_testcase.py | 3 | ||||
-rw-r--r-- | functest/tests/unit/core/test_unit.py | 90 | ||||
-rw-r--r-- | functest/tests/unit/core/test_vnf.py | 7 |
5 files changed, 97 insertions, 61 deletions
diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py index 8de42ec5..0160c8e1 100644 --- a/functest/tests/unit/core/test_feature.py +++ b/functest/tests/unit/core/test_feature.py @@ -17,10 +17,6 @@ import mock from functest.core import feature from functest.core import testcase -# logging must be disabled else it calls time.time() -# what will break these unit tests. -logging.disable(logging.CRITICAL) - class FeatureTestingBase(unittest.TestCase): @@ -95,4 +91,7 @@ class BashFeatureTesting(FeatureTestingBase): if __name__ == "__main__": + # logging must be disabled else it calls time.time() + # what will break these unit tests. + logging.disable(logging.CRITICAL) unittest.main(verbosity=2) diff --git a/functest/tests/unit/core/test_pytest_suite_runner.py b/functest/tests/unit/core/test_pytest_suite_runner.py deleted file mode 100644 index 15e5bd73..00000000 --- a/functest/tests/unit/core/test_pytest_suite_runner.py +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env python - -# 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 - -# pylint: disable=missing-docstring - -import logging -import unittest - -import mock - -from functest.core import pytest_suite_runner -from functest.core import testcase - - -class PyTestSuiteRunnerTesting(unittest.TestCase): - - logging.disable(logging.CRITICAL) - - def setUp(self): - self.psrunner = pytest_suite_runner.PyTestSuiteRunner() - self.result = mock.Mock() - attrs = {'errors': [('test1', 'error_msg1')], - 'failures': [('test2', 'failure_msg1')]} - self.result.configure_mock(**attrs) - - self.pass_results = mock.Mock() - attrs = {'errors': None, - 'failures': None} - self.pass_results.configure_mock(**attrs) - - def test_run(self): - self.psrunner.case_name = 'test_case_name' - with mock.patch('functest.core.pytest_suite_runner.' - 'unittest.TextTestRunner.run', - return_value=self.result): - self.assertEqual(self.psrunner.run(), - testcase.TestCase.EX_OK) - - with mock.patch('functest.core.pytest_suite_runner.' - 'unittest.TextTestRunner.run', - return_value=self.pass_results): - self.assertEqual(self.psrunner.run(), - testcase.TestCase.EX_OK) - - -if __name__ == "__main__": - unittest.main(verbosity=2) diff --git a/functest/tests/unit/core/test_testcase.py b/functest/tests/unit/core/test_testcase.py index 2adf4a6d..ef0983cc 100644 --- a/functest/tests/unit/core/test_testcase.py +++ b/functest/tests/unit/core/test_testcase.py @@ -23,8 +23,6 @@ class TestCaseTesting(unittest.TestCase): """The class testing TestCase.""" # pylint: disable=missing-docstring,too-many-public-methods - logging.disable(logging.CRITICAL) - _case_name = "base" _project_name = "functest" _published_result = "PASS" @@ -225,4 +223,5 @@ class TestCaseTesting(unittest.TestCase): if __name__ == "__main__": + logging.disable(logging.CRITICAL) unittest.main(verbosity=2) diff --git a/functest/tests/unit/core/test_unit.py b/functest/tests/unit/core/test_unit.py new file mode 100644 index 00000000..f86ea8d3 --- /dev/null +++ b/functest/tests/unit/core/test_unit.py @@ -0,0 +1,90 @@ +#!/usr/bin/env python + +# 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 + +# pylint: disable=missing-docstring + +import logging +import unittest + +import mock + +from functest.core import unit +from functest.core import testcase + + +class PyTestSuiteRunnerTesting(unittest.TestCase): + + def setUp(self): + self.psrunner = unit.Suite() + + @mock.patch('unittest.TestLoader') + def _test_run(self, mock_class=None, result=mock.Mock(), + status=testcase.TestCase.EX_OK): + with mock.patch('functest.core.unit.unittest.TextTestRunner.run', + return_value=result): + self.assertEqual(self.psrunner.run(), status) + mock_class.assert_not_called() + + def test_check_suite_null(self): + self.assertEqual(self.psrunner.suite, None) + + def test_run_no_ut(self): + mock_result = mock.Mock(testsRun=0, errors=[], failures=[]) + self._test_run(result=mock_result, + status=testcase.TestCase.EX_RUN_ERROR) + self.assertEqual(self.psrunner.result, 0) + self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []}) + self.assertEqual(self.psrunner.is_successful(), + testcase.TestCase.EX_TESTCASE_FAILED) + + def test_run_result_ko(self): + self.psrunner.criteria = 100 + mock_result = mock.Mock(testsRun=50, errors=[('test1', 'error_msg1')], + failures=[('test2', 'failure_msg1')]) + self._test_run(result=mock_result) + self.assertEqual(self.psrunner.result, 96) + self.assertEqual(self.psrunner.details, + {'errors': [('test1', 'error_msg1')], + 'failures': [('test2', 'failure_msg1')]}) + self.assertEqual(self.psrunner.is_successful(), + testcase.TestCase.EX_TESTCASE_FAILED) + + def test_run_result_ok(self): + mock_result = mock.Mock(testsRun=50, errors=[], + failures=[]) + self._test_run(result=mock_result) + self.assertEqual(self.psrunner.result, 100) + self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []}) + self.assertEqual(self.psrunner.is_successful(), + testcase.TestCase.EX_OK) + + @mock.patch('unittest.TestLoader') + def test_run_name_exc(self, mock_class=None): + mock_obj = mock.Mock(side_effect=ImportError) + mock_class.side_effect = mock_obj + self.assertEqual(self.psrunner.run(name='foo'), + testcase.TestCase.EX_RUN_ERROR) + mock_class.assert_called_once_with() + mock_obj.assert_called_once_with() + + @mock.patch('unittest.TestLoader') + def test_run_name(self, mock_class=None): + mock_result = mock.Mock(testsRun=50, errors=[], + failures=[]) + mock_obj = mock.Mock() + mock_class.side_effect = mock_obj + with mock.patch('functest.core.unit.unittest.TextTestRunner.run', + return_value=mock_result): + self.assertEqual(self.psrunner.run(name='foo'), + testcase.TestCase.EX_OK) + mock_class.assert_called_once_with() + mock_obj.assert_called_once_with() + + +if __name__ == "__main__": + logging.disable(logging.CRITICAL) + unittest.main(verbosity=2) diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py index 793e9576..ce859040 100644 --- a/functest/tests/unit/core/test_vnf.py +++ b/functest/tests/unit/core/test_vnf.py @@ -21,8 +21,6 @@ from functest.core import testcase class VnfBaseTesting(unittest.TestCase): - logging.disable(logging.CRITICAL) - def setUp(self): self.test = vnf.VnfOnBoarding( project='functest', case_name='aaa') @@ -148,12 +146,12 @@ class VnfBaseTesting(unittest.TestCase): def test_deploy_vnf_unimplemented(self): with self.assertRaises(Exception) as context: self.test.deploy_vnf() - self.assertTrue('VNF not deployed' in context.exception) + self.assertIn('VNF not deployed', str(context.exception)) def test_test_vnf_unimplemented(self): with self.assertRaises(Exception) as context: self.test.test_vnf()() - self.assertTrue('VNF not tested' in context.exception) + self.assertIn('VNF not tested', str(context.exception)) def test_parse_results_ex_ok(self): self.test.details['test_vnf']['status'] = 'PASS' @@ -165,4 +163,5 @@ class VnfBaseTesting(unittest.TestCase): if __name__ == "__main__": + logging.disable(logging.CRITICAL) unittest.main(verbosity=2) |