From 48fcc87bde9b62d2464f823ec9d39a530c974441 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Thu, 18 May 2017 17:26:49 +0200 Subject: Use StringIO in odl.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It avoids creating and removing the temporary file to dump robot output. Change-Id: Ia5ea66e76ffb8b8327f2da938f177e8ef4c61dd4 Signed-off-by: Cédric Ollivier --- functest/tests/unit/odl/test_odl.py | 40 ------------------------------------- 1 file changed, 40 deletions(-) (limited to 'functest/tests') diff --git a/functest/tests/unit/odl/test_odl.py b/functest/tests/unit/odl/test_odl.py index e2778e24..6e2e9b1d 100644 --- a/functest/tests/unit/odl/test_odl.py +++ b/functest/tests/unit/odl/test_odl.py @@ -312,8 +312,6 @@ class ODLMainTesting(ODLTesting): def test_run_ko(self, *args): with mock.patch.object(self.test, 'set_robotframework_vars', return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True), \ self.assertRaises(RobotError): self._test_main(testcase.TestCase.EX_RUN_ERROR, *args) @@ -322,71 +320,33 @@ class ODLMainTesting(ODLTesting): def test_parse_results_ko(self, *args): with mock.patch.object(self.test, 'set_robotframework_vars', return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True), \ mock.patch.object(self.test, 'parse_results', side_effect=RobotError): self._test_main(testcase.TestCase.EX_RUN_ERROR, *args) - @mock.patch('os.remove', side_effect=Exception) - @mock.patch('robot.run') - @mock.patch('os.makedirs') - def test_remove_exc(self, *args): - with mock.patch.object(self.test, 'set_robotframework_vars', - return_value=True), \ - mock.patch.object(self.test, 'parse_results'), \ - self.assertRaises(Exception): - self._test_main(testcase.TestCase.EX_OK, *args) - - @mock.patch('os.remove') @mock.patch('robot.run') @mock.patch('os.makedirs') def test_ok(self, *args): with mock.patch.object(self.test, 'set_robotframework_vars', return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True), \ mock.patch.object(self.test, 'parse_results'): self._test_main(testcase.TestCase.EX_OK, *args) - @mock.patch('os.remove') @mock.patch('robot.run') @mock.patch('os.makedirs', side_effect=OSError(errno.EEXIST, '')) def test_makedirs_oserror17(self, *args): with mock.patch.object(self.test, 'set_robotframework_vars', return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True) as mock_open, \ mock.patch.object(self.test, 'parse_results'): self._test_main(testcase.TestCase.EX_OK, *args) - mock_open.assert_called_once_with( - os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+') - @mock.patch('os.remove') @mock.patch('robot.run', return_value=1) @mock.patch('os.makedirs') def test_testcases_in_failure(self, *args): with mock.patch.object(self.test, 'set_robotframework_vars', return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True) as mock_open, \ - mock.patch.object(self.test, 'parse_results'): - self._test_main(testcase.TestCase.EX_OK, *args) - mock_open.assert_called_once_with( - os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+') - - @mock.patch('os.remove', side_effect=OSError) - @mock.patch('robot.run') - @mock.patch('os.makedirs') - def test_remove_oserror(self, *args): - with mock.patch.object(self.test, 'set_robotframework_vars', - return_value=True), \ - mock.patch.object(odl, 'open', mock.mock_open(), - create=True) as mock_open, \ mock.patch.object(self.test, 'parse_results'): self._test_main(testcase.TestCase.EX_OK, *args) - mock_open.assert_called_once_with( - os.path.join(odl.ODLTests.res_dir, 'stdout.txt'), 'w+') class ODLRunTesting(ODLTesting): -- cgit 1.2.3-korg