def test_parse_over_many_interfaces(self): out = SAMPLE_OUTPUT for i in range(150): out += """\n%d: eth%d: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether fa:16:3e:de:ad:be brd ff:ff:ff:ff:ff:ff""" % (i + 4, i + 2) retval = ip._parse_interfaces(out, ['eth']) self.assertEqual(len(retval), 152)
def test_parse_over_many_interfaces(self): out = SAMPLE_OUTPUT for i in range(150): out += """\n%d: eth%d: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000 link/ether fa:16:3e:de:ad:be brd ff:ff:ff:ff:ff:ff""" % (i+4, i+2) retval = ip._parse_interfaces(out, ['eth']) self.assertEqual(len(retval), 152)
def test_parse_interfaces_with_filter(self): with mock.patch.object(ip, '_parse_interface') as parse: parse.side_effect = lambda x: x retval = ip._parse_interfaces(SAMPLE_OUTPUT, ['eth']) self.assertEqual(len(retval), 2) for chunk in retval: assert re.search('^[0-9]: eth', chunk) is not None
def test_parse_interfaces(self): with mock.patch.object(ip, '_parse_interface') as parse: parse.side_effect = lambda x: x retval = ip._parse_interfaces(SAMPLE_OUTPUT) self.assertEqual(len(retval), 3)