From 653e3c4d370475fb9d8f22c209929be91c31507e Mon Sep 17 00:00:00 2001 From: hyades Date: Tue, 3 Sep 2013 22:49:13 +0530 Subject: [PATCH] unittests for make coverage --- python-api/gstswitch/server.py | 2 +- python-api/tests/unittests/test_server.py | 43 ++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/python-api/gstswitch/server.py b/python-api/gstswitch/server.py index 86f323b..cc33154 100644 --- a/python-api/gstswitch/server.py +++ b/python-api/gstswitch/server.py @@ -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, diff --git a/python-api/tests/unittests/test_server.py b/python-api/tests/unittests/test_server.py index 4f0b23f..86bcb61 100644 --- a/python-api/tests/unittests/test_server.py +++ b/python-api/tests/unittests/test_server.py @@ -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 @@ -215,6 +234,14 @@ 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() @@ -222,10 +249,24 @@ def test_kill(self, monkeypatch): 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 \ No newline at end of file + assert s.proc is not None + + def test_make_coverage(self, monkeypatch): + s = Server(path='abc') + monkeypatch.setattr(subprocess, 'Popen', MockPopen) + s.make_coverage() \ No newline at end of file