def test_ip_address_format(): """ Check that the output of ip address conforms to what we expect in order to parse it properly. """ # We force up status so we parse at least one IP of each family subprocess.call(['ip', 'link', 'set', 'dev', 'lo', 'up']) out = subprocess.check_output(['ip', 'address', 'show', 'dev', 'lo']) mac, v4, v6 = _parse_addresses(out) assert mac is not None assert len(mac.split(':')) == 6 assert mac in out assert len(v4) > 0 for a in v4: assert a.version == 4 assert a.with_prefixlen in out assert len(v6) > 0 for a in v6: assert a.version == 6 assert a.with_prefixlen in out # IF status, MAC, inet, valid, inet, valid, ..., inet6, valid, ... assert len(out.strip('\n').split('\n')) == (2 + 2 * len(v4) + 2 * len(v6))