summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Stasiak <jakub@stasiak.at>2020-06-23 12:36:50 +0200
committerJakub Stasiak <jakub@stasiak.at>2020-06-23 12:36:50 +0200
commit2ce9c813f78918968f6c1734b7d0ba524d4855a2 (patch)
treeb7f6bbc305b7f47b575d7332e6651140909caaec
parent54fd603b24a559214e80c564c4d9de2b93d58a13 (diff)
downloadnetaddr-2ce9c813f78918968f6c1734b7d0ba524d4855a2.tar.gz
Fix a regression in spanning_cidr(), spotted by Herman Narkaytismore2
-rw-r--r--netaddr/ip/__init__.py4
-rw-r--r--netaddr/tests/ip/test_ip_v4.py15
2 files changed, 16 insertions, 3 deletions
diff --git a/netaddr/ip/__init__.py b/netaddr/ip/__init__.py
index 75736fb..86c1ed1 100644
--- a/netaddr/ip/__init__.py
+++ b/netaddr/ip/__init__.py
@@ -1692,8 +1692,8 @@ def spanning_cidr(ip_addrs):
"""
ip_addrs_iter = iter(ip_addrs)
try:
- network_a = _iter_next(ip_addrs_iter)
- network_b = _iter_next(ip_addrs_iter)
+ network_a = IPNetwork(_iter_next(ip_addrs_iter))
+ network_b = IPNetwork(_iter_next(ip_addrs_iter))
except StopIteration:
raise ValueError('IP sequence must contain at least 2 elements!')
diff --git a/netaddr/tests/ip/test_ip_v4.py b/netaddr/tests/ip/test_ip_v4.py
index 86e3817..f827704 100644
--- a/netaddr/tests/ip/test_ip_v4.py
+++ b/netaddr/tests/ip/test_ip_v4.py
@@ -5,7 +5,7 @@ import sys
import pytest
-from netaddr import IPAddress, IPNetwork, INET_PTON, AddrFormatError, ZEROFILL, Z, P, NOHOST
+from netaddr import IPAddress, IPNetwork, INET_PTON, spanning_cidr, AddrFormatError, ZEROFILL, Z, P, NOHOST
def test_ipaddress_v4():
@@ -532,3 +532,16 @@ def test_ipnetwork_change_netmask():
ip = IPNetwork('dead:beef::/16')
ip.netmask = 'ffff:ffff:ffff:ffff::'
assert ip.prefixlen == 64
+
+
+def test_spanning_cidr_handles_strings():
+ # This that a regression introduced in 0fda41a is fixed. The regression caused an error when str
+ # addresses were passed to the function.
+ addresses = [
+ IPAddress('10.0.0.1'),
+ IPAddress('10.0.0.2'),
+ '10.0.0.3',
+ '10.0.0.4',
+ ]
+ assert spanning_cidr(addresses) == IPNetwork('10.0.0.0/29')
+ assert spanning_cidr(reversed(addresses)) == IPNetwork('10.0.0.0/29')