Commit 6e3e1308 authored by Jason Frisvold's avatar Jason Frisvold
Browse files

- Add unit test for pid_exists()

parent 06b4fac4
......@@ -19,9 +19,47 @@
# * 02110-1301 USA * #
import pytest
import errno
import os
from libs import funcs
from libs.funcs import pid_exists
from mock import patch
class TestFuncs(object):
def test_pid_exists(self):
def test_pid_negative(self):
assert pid_exists(-1) == False
def test_pid_zero(self):
with pytest.raises(ValueError):
def test_pid_typeerror(self):
with pytest.raises(TypeError):
def test_pid_exists(self, oskillobj):
oskillobj.return_value = None
assert pid_exists(100) == True
def test_pid_does_not_exist(self, oskillobj):
oskillobj.side_effect = OSError(errno.ESRCH, 'No such process')
assert pid_exists(1234) == False
def test_pid_no_permissions(self, oskillobj):
oskillobj.side_effect = OSError(errno.EPERM, 'Operation not permitted')
assert pid_exists(1234) == True
def test_pid_invalid(self, oskillobj):
oskillobj.side_effect = OSError(errno.EINVAL, 'Invalid argument')
with pytest.raises(OSError):
def test_pid_os_typeerror(self, oskillobj):
oskillobj.side_effect = TypeError('an integer is required (got type str)')
with pytest.raises(TypeError):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment