Skip to content

Commit

Permalink
Add tests for a set
Browse files Browse the repository at this point in the history
  • Loading branch information
Miauwkeru committed Oct 8, 2024
1 parent 76246db commit ce1e705
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test_fieldtype_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,18 @@ def test_record_ipaddress():
assert TestRecord("192.168.0.1").ip == "192.168.0.1"
assert TestRecord("255.255.255.255").ip == "255.255.255.255"
assert hash(TestRecord("192.168.0.1").ip) == hash(net.ipaddress("192.168.0.1"))

# ipv6
assert TestRecord("::1").ip == "::1"
assert TestRecord("2001:4860:4860::8888").ip == "2001:4860:4860::8888"
assert TestRecord("2001:4860:4860::4444").ip == "2001:4860:4860::4444"

# Test whether it functions in a set
data = {TestRecord(ip).ip for ip in ["192.168.0.1", "192.168.0.1", "::1", "::1"]}
assert len(data) == 2
assert net.ipaddress("::1") in data
assert net.ipaddress("192.168.0.1") in data

# instantiate from different types
assert TestRecord(1).ip == "0.0.0.1"
assert TestRecord(0x7F0000FF).ip == "127.0.0.255"
Expand Down Expand Up @@ -112,6 +119,13 @@ def test_record_ipnetwork():
assert "64:ff9b::0.0.0.0" in r.subnet
assert "64:ff9b::255.255.255.255" in r.subnet

# Test whether it functions in a set
data = {TestRecord(x).subnet for x in ["192.168.0.0/24", "192.168.0.0/24", "::1", "::1"]}
assert len(data) == 2
assert net.ipnetwork("::1") in data
assert net.ipnetwork("192.168.0.0/24") in data
assert "::1" not in data


@pytest.mark.parametrize("PSelector", [Selector, CompiledSelector])
def test_selector_ipaddress(PSelector):
Expand Down

0 comments on commit ce1e705

Please sign in to comment.