Skip to content

Commit

Permalink
Added unittests server.py - 100% coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Jul 22, 2013
1 parent fab6c53 commit 9c74a37
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 14 deletions.
19 changes: 5 additions & 14 deletions python-api/gstswitch/server.py
Expand Up @@ -105,14 +105,11 @@ def record_file(self, record_file):
if not record_file:
raise ValueError("Record File '{0}' cannot be blank".format(record_file))
else:
try:
rec = str(record_file)
if rec.find('/') < 0:
self._record_file = rec
else:
raise ValueError("Record File: '{0}' cannot have forward slashes".format(rec))
except TypeError:
raise TypeError("Record File cannot be '{0}'".format(type(record_file)))
rec = str(record_file)
if rec.find('/') < 0:
self._record_file = rec
else:
raise ValueError("Record File: '{0}' cannot have forward slashes".format(rec))

def run(self, gst_option=''):
"""Launch the server process
Expand Down Expand Up @@ -181,7 +178,6 @@ def terminate(self):
"""
print 'Killing server'
proc = self.proc
ret = False
if proc is None:
raise ServerProcessError('Server Process does not exist')
else:
Expand All @@ -192,8 +188,6 @@ def terminate(self):
return True
except OSError:
raise ServerProcessError('Cannot terminate server process. Try killing it')
return False
return ret

def kill(self):
"""Kill the server process by sending signal.SIGKILL
Expand All @@ -207,12 +201,9 @@ def kill(self):
if self.proc is None:
raise ServerProcessError('Server Process does not exist')
else:
ret = False
try:
os.kill(self.pid, signal.SIGKILL)
self.proc = None
return True
except OSError:
raise ServerProcessError('Cannot kill process')
return False
return ret
36 changes: 36 additions & 0 deletions python-api/gstswitch/test_server.py
Expand Up @@ -91,6 +91,22 @@ def test_invalid_control_port_range(self):
Server(path=path, control_port=control_port)


class TestRecordFile(object):
# Record File
def test_record_file_blank(self):
files = ['', None, [], {}]
path = '/home/hyades/gst/master/gstreamer/tools/'
for record_file in files:
with pytest.raises(ValueError):
Server(path=path, record_file=record_file)

def test_record_file_slashes(self):
file = 'abcd/xyz/'
with pytest.raises(ValueError):
path = '/home/hyades/gst/master/gstreamer/tools/'
Server(path=path, record_file=file)


class TestProcess(object):
# OS Errors
def test_terminate_fail(self):
Expand All @@ -107,6 +123,26 @@ def terminate(self):
with pytest.raises(ServerProcessError):
s.terminate()

def test_kill_fail(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
s.proc = 1
s.pid = -300
with pytest.raises(ServerProcessError):
s.kill()

def test_start_process(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
with pytest.raises(ServerProcessError):
s._start_process('/usr/')

def test_no_process_kill(self):
path = '/home/hyades/gst/master/gstreamer/tools/'
s = Server(path=path)
with pytest.raises(ServerProcessError):
s.kill()


class TestNormal(object):
# Normal Functioning Tests
Expand Down

0 comments on commit 9c74a37

Please sign in to comment.