From 99212af1fb82340a1571f98b41ecddcb95343017 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Tue, 23 May 2017 16:54:14 +0200 Subject: Rename test_pytest_suite_runner.py to test_unit.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It conforms with [1]. [1] https://gerrit.opnfv.org/gerrit/#/c/35211/ Change-Id: Ife7a161970997cf6cd74e86c343d4879f87b5cf4 Signed-off-by: Cédric Ollivier --- .../tests/unit/core/test_pytest_suite_runner.py | 90 ---------------------- functest/tests/unit/core/test_unit.py | 90 ++++++++++++++++++++++ 2 files changed, 90 insertions(+), 90 deletions(-) delete mode 100644 functest/tests/unit/core/test_pytest_suite_runner.py create mode 100644 functest/tests/unit/core/test_unit.py (limited to 'functest') 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 c11d8853..00000000 --- a/functest/tests/unit/core/test_pytest_suite_runner.py +++ /dev/null @@ -1,90 +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 unit -from functest.core import testcase - - -class PyTestSuiteRunnerTesting(unittest.TestCase): - - def setUp(self): - self.psrunner = unit.PyTestSuiteRunner() - - @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_unit.py b/functest/tests/unit/core/test_unit.py new file mode 100644 index 00000000..c11d8853 --- /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.PyTestSuiteRunner() + + @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) -- cgit 1.2.3-korg