def test__no_ip_raises_ipaddressnotavailable(self): mock_ioerror = IOError() mock_ioerror.errno = errno.EADDRNOTAVAIL self.patch(detect_module.fcntl, "ioctl").side_effect = mock_ioerror sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) with ExpectedException(IPAddressNotAvailable, ".*No IP address.*"): get_interface_ip(sock, "lo")
def test__unknown_errno_ip_raises_ipaddressnotavailable(self): mock_ioerror = IOError() mock_ioerror.errno = errno.EACCES self.patch(detect_module.fcntl, "ioctl").side_effect = mock_ioerror sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # Drive-by test for the strerror() call. with ExpectedException(IPAddressNotAvailable, "Failed.*Permission denied."): get_interface_ip(sock, "lo")
def test__invalid_interface_raises_interfacenotfound(self): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) with ExpectedException(detect_module.InterfaceNotFound): get_interface_ip(sock, factory.make_unicode_string(size=15))
def test_loopback_has_localhost_address(self): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.assertEqual("127.0.0.1", get_interface_ip(sock, "lo"))