Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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