def test_kill(self, monkeypatch): """Test kill ServerProcessError""" serv = Server(path='abc') serv.proc = Mock() monkeypatch.setattr(os, 'kill', Mock(side_effect=OSError)) with pytest.raises(ServerProcessError): serv.kill()
def test_kill_fail(self): """Test when kill fails""" serv = Server(path=PATH) serv.proc = 1 serv.pid = -300 with pytest.raises(ServerProcessError): serv.kill()
def test_gcov_flush_fail(self): """Test when gcov_flush fails""" serv = Server(path=PATH) serv.proc = 1 serv.pid = -300 with pytest.raises(ServerProcessError): serv.gcov_flush()
def test_gov_flush_fail(self): """Test when gov_flush fails""" serv = Server(path=PATH) serv.proc = Mock(ProcessMonitor) serv.proc.send_signal.side_effect = OSError with pytest.raises(ServerProcessError): serv.gcov_flush()
def test_normal_gcov_flush(self, monkeypatch): """Test gcov_flush""" serv = Server(path='abc') serv.proc = Mock() monkeypatch.setattr(os, 'kill', Mock()) res = serv.gcov_flush() assert res is True assert serv.proc is not None
def test_terminate_cov(self): """Test terminate and gcov_flush ServerProcessError""" serv = Server(path='abc') serv.proc = MockProcess(False) serv.gcov_flush = Mock() serv.make_coverage = Mock() with pytest.raises(ServerProcessError): serv.terminate(True)
def test_normal_kill(self, monkeypatch): """Test kill when normally called""" serv = Server(path='abc') serv.proc = Mock() monkeypatch.setattr(os, 'kill', Mock()) res = serv.kill() assert res is True assert serv.proc is None
def test_is_not_alive(self, monkeypatch): """ Test that is_alive returns True when the underlying proc returns None on Poll """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, "poll", Mock(return_value=123)) assert serv.is_alive() is False
def test_is_not_alive(self, monkeypatch): """ Test that is_alive returns True when the underlying proc returns None on Poll """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, 'poll', Mock(return_value=123)) assert serv.is_alive() is False
def test_kill_cov(self, monkeypatch): """Test kill and gcov_flush ServerProcessError""" serv = Server(path='abc') serv.proc = MockProcess(False) serv.gcov_flush = Mock() serv.make_coverage = Mock() monkeypatch.setattr(os, 'kill', Mock(side_effect=OSError)) with pytest.raises(ServerProcessError): serv.kill(True)
def test_args_are_passed(self, monkeypatch): """ Test that wait_for_output passes all Arguments to the underlying ProcessMonitor """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, "wait_for_output", Mock()) serv.wait_for_output("foo", timeout=123, count=456) serv.proc.wait_for_output.called_once_with("foo", timeout=123, count=456)
def test_error_is_passed(self, monkeypatch): """ Test that wait_for_output passes all Exceptions from the underlying ProcessMonitor """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, "wait_for_output", Mock(side_effect=MatchTimeoutError)) with pytest.raises(MatchTimeoutError): serv.wait_for_output("foo", timeout=123, count=456)
def test_error_is_passed(self, monkeypatch): """ Test that wait_for_output passes all Exceptions from the underlying ProcessMonitor """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, 'wait_for_output', Mock(side_effect=MatchTimeoutError)) with pytest.raises(MatchTimeoutError): serv.wait_for_output("foo", timeout=123, count=456)
def test_args_are_passed(self, monkeypatch): """ Test that wait_for_output passes all Arguments to the underlying ProcessMonitor """ serv = Server() serv.proc = Mock() monkeypatch.setattr(serv.proc, 'wait_for_output', Mock()) serv.wait_for_output("foo", timeout=123, count=456) serv.proc.wait_for_output.called_once_with("foo", timeout=123, count=456)
def test_terminate_fail(self): """Test when terminate fails""" class FakeProc(object): """A mock process""" def __init__(self): pass def terminate(self): """Terminate the mock process""" raise OSError serv = Server(path=PATH) serv.proc = FakeProc() with pytest.raises(ServerProcessError): serv.terminate()
def test_normal_terminate(self): """Test terminal when normally called""" serv = Server(path='abc') serv.proc = MockProcess(True) serv.terminate() assert serv.proc is None
def test_terminate(self): """Test terminate ServerProcessError""" serv = Server(path='abc') serv.proc = MockProcess(False) with pytest.raises(ServerProcessError): serv.terminate()