# Path: pushmanager/core/pid.py
# def is_process_alive(pid):
# def kill_processes(pids):
# def check(path):
# def write(path, append=False, pid=None):
# def remove(path):


import contextlib
import errno
import mock
import testify as T
from exceptions import OSError
from pushmanager.core import pid
        with mock.patch(method) as mocked_method:
            mocked_method.return_value = return_value
            mocked_method.side_effect = side_effect
            yield

    def test_process_is_alive(self):
        with self.mock_method('%s.pid.os.kill' % __name__, None, None):
            assert pid.is_process_alive(1)

    def test_is_process_alive_permission_error(self):
        def side_effect(x, y):
            raise OSError(errno.EPERM, "Access denied")

        with self.mock_method('%s.pid.os.kill' % __name__, None, side_effect):
            assert pid.is_process_alive(1)

    def test_is_process_alive_generic_error(self):
        def side_effect(x, y):
            raise Exception("fake error for testing")

        with self.mock_method('%s.pid.os.kill' % __name__, None, side_effect):
            T.assert_equal(pid.is_process_alive(1), False)

    def test_kill_processes(self):
        with contextlib.nested(
                self.mock_method('%s.pid.os.kill' % __name__, None, None),
                self.mock_method('%s.pid.is_process_alive' % __name__, False, None)
        ):
            # this should run fine, all processes are dead
            pids = [1, 2, 3, 4, 5]

# Path: pushmanager/core/pid.py
# def is_process_alive(pid):
# def kill_processes(pids):
# def check(path):
# def write(path, append=False, pid=None):
# def remove(path):


# Path: pushmanager/tests/test_core_pid.py
import contextlib
import errno
import mock
import testify as T
from exceptions import OSError
from pushmanager.core import pid

        with mock.patch(method) as mocked_method:
            mocked_method.return_value = return_value
            mocked_method.side_effect = side_effect
            yield

    def test_process_is_alive(self):
        with self.mock_method('%s.pid.os.kill' % __name__, None, None):
            assert pid.is_process_alive(1)

    def test_is_process_alive_permission_error(self):
        def side_effect(x, y):
            raise OSError(errno.EPERM, "Access denied")

        with self.mock_method('%s.pid.os.kill' % __name__, None, side_effect):
            assert pid.is_process_alive(1)

    def test_is_process_alive_generic_error(self):
        def side_effect(x, y):
            raise Exception("fake error for testing")

        with self.mock_method('%s.pid.os.kill' % __name__, None, side_effect):
            T.assert_equal(pid.is_process_alive(1), False)

    def test_kill_processes(self):
        with contextlib.nested(
                self.mock_method('%s.pid.os.kill' % __name__, None, None),
                self.mock_method('%s.pid.is_process_alive' % __name__, False, None)
        ):
            # this should run fine, all processes are dead
            pids = [1, 2, 3, 4, 5]

            pid.kill_processes(pids)