Skip to content

Commit

Permalink
unittests for make coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
hyades committed Sep 3, 2013
1 parent 1f3a4b4 commit 653e3c4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python-api/gstswitch/server.py
Expand Up @@ -218,7 +218,7 @@ def _start_process(self, cmd):
def make_coverage(self):
cmd = 'make -C {0} coverage'.format(TOOLS_DIR)
print TOOLS_DIR
with open(os.devnull, 'w') as tempf:
with open(os.devnull, 'w'):
proc = subprocess.Popen(
cmd.split(),
bufsize=-1,
Expand Down
43 changes: 42 additions & 1 deletion python-api/tests/unittests/test_server.py
Expand Up @@ -191,6 +191,25 @@ def terminate(self):
if self.mode == False:
raise OSError('Testing terminate')

def kill(selfd):
if self.mode == True:
pass
if self.mode == False:
raise OSError('Testing kill')

def make_coverage(self):
pass



class MockPopen(object):
def __init__(self, cmd, bufsize, shell):
pass

def communicate(self):
return 0, 0



class TestNormal(object):
# Normal Functioning Tests
Expand All @@ -215,17 +234,39 @@ def test_terminate(self):
with pytest.raises(ServerProcessError):
s.terminate()

def test_terminate_cov(self):
s = Server(path='abc')
s.proc = MockProcess(False)
s.gcov_flush = Mock()
s.make_coverage = Mock()
with pytest.raises(ServerProcessError):
s.terminate(True)

def test_kill(self, monkeypatch):
s = Server(path='abc')
s.proc = Mock()
monkeypatch.setattr(os, 'kill', Mock(side_effect=OSError))
with pytest.raises(ServerProcessError):
s.kill()

def test_kill_cov(self, monkeypatch):
s = Server(path='abc')
s.proc = MockProcess(False)
s.gcov_flush = Mock()
s.make_coverage = Mock()
monkeypatch.setattr(os, 'kill', Mock(side_effect=OSError))
with pytest.raises(ServerProcessError):
s.kill(True)

def test_normal_gcov_flush(self, monkeypatch):
s = Server(path='abc')
s.proc = Mock()
monkeypatch.setattr(os, 'kill', Mock())
res = s.gcov_flush()
assert res == True
assert s.proc is not None
assert s.proc is not None

def test_make_coverage(self, monkeypatch):
s = Server(path='abc')
monkeypatch.setattr(subprocess, 'Popen', MockPopen)
s.make_coverage()

0 comments on commit 653e3c4

Please sign in to comment.