add test_terminate_subprocess1 for unit test

Change-Id: Ibf1b42c7c41aacb4f5d5cb8d2699cb069436f230
This commit is contained in:
gecong1973 2021-02-04 16:22:37 -08:00
parent 543eb4c26c
commit 6e0bed5926
1 changed files with 13 additions and 0 deletions

View File

@ -93,6 +93,19 @@ class TestUtils(unittest.TestCase):
ret = utils.get_active_jobs_from_api(self.client)
self.assertEqual(job_list, ret)
@patch('os.kill')
@patch('psutil.Process')
def test_terminate_subprocess1(self, mock_process, mock_oskill):
mock_pro = mock.MagicMock()
mock_pro.name.startswith.return_value = False
mock_process.return_value = mock_pro
result = utils.terminate_subprocess(35, 'test')
self.assertIsNone(result)
mock_pro.name.startswith.return_value = True
mock_oskill.side_effect = Exception("error")
result = utils.terminate_subprocess(35, 'test')
self.assertIsNone(result)
@patch('psutil.Process')
def test_terminate_subprocess(self, mock_process_constructor):
mock_pro = mock_process_constructor.return_value