Пример #1
0
def test_socket_address():
    """
    Test basic SocketAddress operations: initialization and equivalence.
    """
    address = SocketAddress('127.0.0.1', 1234)
    # Equivalence
    assert address == SocketAddress('127.0.0.1', 1234)
    assert address != SocketAddress('127.0.0.0', 1234)
    assert address != SocketAddress('127.0.0.1', 1230)
    assert not address == 'foo'
    assert address != 'foo'
Пример #2
0
    This conversion should cause an exception raising.
    """
    with pytest.raises(ValueError):
        address_to_host_port(1.234)


@pytest.mark.parametrize(
    ('address', 'host', 'port'),
    [
        (None, None, None),
        (
            AgentAddress('tcp', '127.0.0.1:123', 'PUSH', 'server', 'pickle'),
            '127.0.0.1',
            123,
        ),
        (SocketAddress('127.0.0.1', 123), '127.0.0.1', 123),
        ('127.0.0.1:123', '127.0.0.1', 123),
        ('127.0.0.1', '127.0.0.1', None),
        (
            namedtuple('Foo', ['host', 'port'])('127.0.0.1', 123),
            '127.0.0.1',
            123,
        ),
    ],
)
def test_valid_address_to_host_port(address, host, port):
    """
    Test conversion of an address to its corresponding host+port tuple.
    """
    assert address_to_host_port(address) == (host, port)