diff options
-rw-r--r-- | xtesting/core/behaveframework.py | 29 | ||||
-rw-r--r-- | xtesting/tests/unit/core/test_behaveframework.py | 36 | ||||
-rw-r--r-- | xtesting/tests/unit/core/test_testcase.py | 1 |
3 files changed, 27 insertions, 39 deletions
diff --git a/xtesting/core/behaveframework.py b/xtesting/core/behaveframework.py index ede3883f..2b41614c 100644 --- a/xtesting/core/behaveframework.py +++ b/xtesting/core/behaveframework.py @@ -43,14 +43,8 @@ class BehaveFramework(testcase.TestCase): def parse_results(self): """Parse output.json and get the details in it.""" - - try: - with open(self.json_file) as stream_: - self.response = json.load(stream_) - except IOError: - self.__logger.error("Error reading the file %s", self.json_file) - - try: + with open(self.json_file) as stream_: + self.response = json.load(stream_) if self.response: self.total_tests = len(self.response) for item in self.response: @@ -60,21 +54,14 @@ class BehaveFramework(testcase.TestCase): self.fail_tests += 1 elif item['status'] == 'skipped': self.skip_tests += 1 - except KeyError: - self.__logger.error("Error in json - %s", self.response) - - try: self.result = 100 * ( self.pass_tests / self.total_tests) - except ZeroDivisionError: - self.__logger.error("No test has been run") - - self.details = {} - self.details['total_tests'] = self.total_tests - self.details['pass_tests'] = self.pass_tests - self.details['fail_tests'] = self.fail_tests - self.details['skip_tests'] = self.skip_tests - self.details['tests'] = self.response + self.details = {} + self.details['total_tests'] = self.total_tests + self.details['pass_tests'] = self.pass_tests + self.details['fail_tests'] = self.fail_tests + self.details['skip_tests'] = self.skip_tests + self.details['tests'] = self.response def run(self, **kwargs): """Run the BehaveFramework feature files diff --git a/xtesting/tests/unit/core/test_behaveframework.py b/xtesting/tests/unit/core/test_behaveframework.py index c4ab2f7c..414d96b5 100644 --- a/xtesting/tests/unit/core/test_behaveframework.py +++ b/xtesting/tests/unit/core/test_behaveframework.py @@ -32,28 +32,27 @@ class ParseResultTesting(unittest.TestCase): self.test = behaveframework.BehaveFramework( case_name='behave', project_name='xtesting') - def test_raises_exc_open(self): - self.test.json_file = 'dummy_file' - self.test.response = self._response - with mock.patch('six.moves.builtins.open', - mock.mock_open()) as mock_file: - mock_file.side_effect = IOError() - self.assertRaises(IOError, self.test.parse_results()) - mock_file.assert_called_once_with('dummy_file') - - def test_raises_exc_key(self): - with mock.patch('six.moves.builtins.open', mock.mock_open()), \ - mock.patch('json.load', return_value=[{'foo': 'bar'}]): - self.assertRaises(KeyError, self.test.parse_results()) + @mock.patch('six.moves.builtins.open', side_effect=OSError) + def test_raises_exc_open(self, *args): # pylint: disable=unused-argument + with self.assertRaises(OSError): + self.test.parse_results() - def test_raises_exe_zerodivision(self): - with mock.patch('six.moves.builtins.open', mock.mock_open()), \ - mock.patch('json.load', mock.Mock(return_value=[])): - self.assertRaises(ZeroDivisionError, self.test.parse_results()) + @mock.patch('json.load', return_value=[{'foo': 'bar'}]) + @mock.patch('six.moves.builtins.open', mock.mock_open()) + def test_raises_exc_key(self, *args): # pylint: disable=unused-argument + with self.assertRaises(KeyError): + self.test.parse_results() + + @mock.patch('json.load', return_value=[]) + @mock.patch('six.moves.builtins.open', mock.mock_open()) + def test_raises_exe_zerodivision(self, *args): + # pylint: disable=unused-argument + with self.assertRaises(ZeroDivisionError): + self.test.parse_results() def _test_result(self, response, result): with mock.patch('six.moves.builtins.open', mock.mock_open()), \ - mock.patch('json.load', mock.Mock(return_value=response)): + mock.patch('json.load', return_value=response): self.test.parse_results() self.assertEqual(self.test.result, result) @@ -171,6 +170,7 @@ class RunTesting(unittest.TestCase): self._test_parse_results(self.test.EX_RUN_ERROR) mock_method.assert_called_once_with() + if __name__ == "__main__": logging.disable(logging.CRITICAL) unittest.main(verbosity=2) diff --git a/xtesting/tests/unit/core/test_testcase.py b/xtesting/tests/unit/core/test_testcase.py index f3b2d512..63bfc3fe 100644 --- a/xtesting/tests/unit/core/test_testcase.py +++ b/xtesting/tests/unit/core/test_testcase.py @@ -449,6 +449,7 @@ class TestCaseTesting(unittest.TestCase): ExtraArgs={'ContentType': 'text/plain'})] self.assertEqual(args[1].mock_calls, expected) + if __name__ == "__main__": logging.disable(logging.CRITICAL) unittest.main(verbosity=2) |