Esempio n. 1
0
    def testMultipleItems(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

        iface1 = jobs_pb2.Interface()
        iface1.mac_address = b'\xaa\x12\x42\xff\xa5\xd0'
        iface1.ifname = 'foo'
        iface1.addresses.extend([address1])

        iface2 = jobs_pb2.Interface()
        iface2.mac_address = b'\xaa\x12\x42\xff\xa5\xd1'
        iface2.ifname = 'bar'
        iface2.addresses.extend([address2])

        ifaces = representer.InterfaceList([iface1, iface2])

        out = io.StringIO()
        ifaces._repr_pretty_(pretty.PrettyPrinter(out), cycle=False)

        expected = """
foo (MAC: aa:12:42:ff:a5:d0):
    inet 42.0.255.32

bar (MAC: aa:12:42:ff:a5:d1):
    inet6 2001:db8::1000
"""
        self.assertEqual(out.getvalue(), expected)
Esempio n. 2
0
 def ifaces(self) -> Sequence[jobs_pb2.Interface]:
     if self._summary is not None:
         return representer.InterfaceList(self._summary.interfaces)
     return representer.InterfaceList(self._client.data.interfaces)
Esempio n. 3
0
 def ifaces(self):
     if self._summary is not None:
         return representer.InterfaceList(self._summary.interfaces)
     return representer.InterfaceList(self._client.data.interfaces)
Esempio n. 4
0
    def testSlice(self):
        iface1 = jobs_pb2.Interface()
        iface2 = jobs_pb2.Interface()

        ifaces = representer.InterfaceList([iface1, iface2])
        self.assertIsInstance(ifaces[:1], representer.InterfaceList)
Esempio n. 5
0
    def testCycle(self):
        ifaces = representer.InterfaceList([])

        out = io.StringIO()
        with self.assertRaises(AssertionError):
            ifaces._repr_pretty_(pretty.PrettyPrinter(out), cycle=True)
Esempio n. 6
0
    def testEmptyResults(self):
        ifaces = representer.InterfaceList([])

        out = io.StringIO()
        ifaces._repr_pretty_(pretty.PrettyPrinter(out), cycle=False)
        self.assertEqual(out.getvalue(), 'No results.')