def test_too_many_octets(self): """ Test that an IP address with too many octets causes an exception to be raised""" ipaddrstr = '192.168.1.1.1' self.assertRaises(netaddr.AddrFormatError, lambda: token.ipv4_str_to_int(ipaddrstr))
def test_random_string(self): """ Test that passing a random string causes an exception to be raised. """ ipaddrstr = 'Bacon' self.assertRaises(netaddr.AddrFormatError, lambda: token.ipv4_str_to_int(ipaddrstr))
def test_invalid_octet(self): """ Test that an IP address with an octet out of range causes an exception to be raised. """ ipaddrstr = '255.255.255.256' self.assertRaises(netaddr.AddrFormatError, lambda: token.ipv4_str_to_int(ipaddrstr))
def test_max(self): """ Test than an IP of 255.255.255.255 has an int value of 4294967295. """ ipaddrstr = '255.255.255.255' ipaddrintexp = 4294967295 ipaddrint = token.ipv4_str_to_int(ipaddrstr) self.assertEqual(ipaddrint, ipaddrintexp)
def test_normal(self): """ Test that a normal IPv4 address gives us the expected int result. """ ipaddrstr = '10.2.0.1' ipaddrintexp = 167903233 ipaddrint = token.ipv4_str_to_int(ipaddrstr) self.assertEqual(ipaddrint, ipaddrintexp)
def test_zeros(self): """ Test that an IP of 0.0.0.0 has an int value of 0. """ ipaddrstr = '0.0.0.0' ipaddrintexp = 0 ipaddrint = token.ipv4_str_to_int(ipaddrstr) self.assertEqual(ipaddrint, ipaddrintexp)