def test_parse(): def assert_kosher(addr): assert addr.host == 'localhost' assert addr.port == 1234 addr = Address.parse('localhost:1234') assert_kosher(addr) addr = Address.parse('localhost', 1234) assert_kosher(addr) addr = Address.parse(('localhost', 1234)) assert_kosher(addr) addr = Address.from_address(addr) assert_kosher(addr)
def test_from_tuple(): addr = Address.from_tuple(('localhost', 1234)) assert addr.host == 'localhost' assert addr.port == 1234 with pytest.raises(Address.InvalidFormat): addr = Address.from_tuple('localhost', 1234) with pytest.raises(Address.InvalidFormat): addr = Address.from_tuple('localhost') with pytest.raises(Address.InvalidFormat): addr = Address.from_tuple(('localhost', 1), 2, 3, 4)
def test_from_string(): addr = Address.from_string('localhost:1234') assert addr.host == 'localhost' assert addr.port == 1234 addr = Address.from_string('localhost: 1234') assert addr.host == 'localhost' assert addr.port == 1234 with pytest.raises(Address.InvalidFormat): Address.from_string('localhost:') with pytest.raises(Address.InvalidFormat): Address.from_string('localhost:-1') with pytest.raises(Address.InvalidFormat): Address.from_string('localhost:beeblebrox') with pytest.raises(Address.InvalidFormat): Address.from_string('localhost:beeblebrox', host='localhost')
def test_from_address(): addr = Address.from_tuple(('localhost', 1234)) addr = Address.from_address(addr) assert addr.host == 'localhost' assert addr.port == 1234