Exemple #1
0
    def test_kill_process(self, process_exists, mock_get_process):
        if not process_exists:
            mock_get_process.return_value = None

        utils.kill_process(mock.sentinel.pid, mock.sentinel.signal,
                           run_as_root=False)

        mock_get_process.assert_called_once_with(mock.sentinel.pid)
        if process_exists:
            mock_get_process.return_value.Terminate.assert_called_once_with()
Exemple #2
0
    def test_kill_process_exception(self, process_still_running,
                                    mock_get_process):
        mock_process = mock.Mock()
        mock_process.Terminate.side_effect = OSError

        mock_get_process.side_effect = [
            mock_process, mock_process if process_still_running else None
        ]

        if process_still_running:
            self.assertRaises(OSError, utils.kill_process, mock.sentinel.pid,
                              mock.sentinel.signal)
        else:
            utils.kill_process(mock.sentinel.pid, mock.sentinel.signal)
Exemple #3
0
    def test_kill_process_exception(self, process_still_running,
                                    mock_get_process):
        mock_process = mock.Mock()
        mock_process.Terminate.side_effect = OSError

        mock_get_process.side_effect = [
            mock_process,
            mock_process if process_still_running else None]

        if process_still_running:
            self.assertRaises(OSError,
                              utils.kill_process,
                              mock.sentinel.pid,
                              mock.sentinel.signal)
        else:
            utils.kill_process(mock.sentinel.pid,
                               mock.sentinel.signal)