def test_read_timeout(): mocked_socket = mock.Mock() mocked_socket.recv.side_effect = mod.socket.timeout try: mod.read(mocked_socket) assert False, 'Timeout was expected' except socket.timeout: pass
def test_read_success(): data = 'something' def mocked_recv(size): if hasattr(mocked_recv, 'called'): return '\0' mocked_recv.called = True return data mocked_socket = mock.Mock() mocked_socket.recv.side_effect = mocked_recv result = mod.read(mocked_socket) assert result == data