def testMultipleAddresses(self): ipv4 = ipaddress.IPv4Address('42.0.255.32') address1 = jobs_pb2.NetworkAddress() address1.address_type = jobs_pb2.NetworkAddress.INET address1.packed_bytes = ipv4.packed ipv6 = ipaddress.IPv6Address('2001:db8::1000') address2 = jobs_pb2.NetworkAddress() address2.address_type = jobs_pb2.NetworkAddress.INET6 address2.packed_bytes = ipv6.packed iface = jobs_pb2.Interface() iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0' iface.ifname = 'foo' iface.addresses.extend([address1, address2]) out = io.StringIO() pp = pretty.PrettyPrinter(out) representer.interface_pretty(iface, pp, cycle=False) expected = """\ foo (MAC: aa:12:42:ff:a5:d0): inet 42.0.255.32 inet6 2001:db8::1000 """ self.assertEqual(out.getvalue(), expected)
def testNoAddresses(self): iface = jobs_pb2.Interface() iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0' iface.ifname = 'foo' out = io.StringIO() pp = pretty.PrettyPrinter(out) representer.interface_pretty(iface, pp, cycle=False) expected = """\ foo (MAC: aa:12:42:ff:a5:d0): """ self.assertEqual(out.getvalue(), expected)
def testSingleAddress(self): ipv4 = ipaddress.IPv4Address('42.0.255.32') address = jobs_pb2.NetworkAddress() address.address_type = jobs_pb2.NetworkAddress.INET address.packed_bytes = ipv4.packed iface = jobs_pb2.Interface() iface.mac_address = b'\xaa\x12\x42\xff\xa5\xd0' iface.ifname = 'foo' iface.addresses.extend([address]) out = StringIO() pp = pretty.PrettyPrinter(out) representer.interface_pretty(iface, pp, cycle=False) expected = """\ foo (MAC: aa:12:42:ff:a5:d0): inet 42.0.255.32 """ self.assertEqual(out.getvalue(), expected)