From b2c3ee8560d3f98f668007c1bcb55b6194e631c4 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Sat, 4 Jan 2020 16:30:07 +0100 Subject: Fix behave driver and its related unit tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I466d655162c1ddd5f4e3ef0e356a27007bfaea0f Signed-off-by: Cédric Ollivier --- xtesting/tests/unit/core/test_behaveframework.py | 36 ++++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'xtesting/tests/unit/core/test_behaveframework.py') 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) -- cgit 1.2.3-korg