python-netifaces/tests/test_netifaces.py
Sudhir Menon c25cc08799 Adding gating.yaml and tests for python-netifaces
Signed-off-by: Sudhir Menon <sumenon@redhat.com>
2024-06-26 14:08:50 +05:30

31 lines
633 B
Python

import netifaces
import pytest
def test_interfaces():
ifaces = netifaces.interfaces()
assert isinstance(ifaces, list)
assert "lo" in ifaces
@pytest.mark.parametrize(
"iface,af,expected",
[
("lo", netifaces.AF_INET, "127.0.0.1"),
("lo", netifaces.AF_INET6, "::1"),
],
)
def test_ifaddresses_lo(iface, af, expected):
addrs = netifaces.ifaddresses(iface)
assert addrs[af][0]["addr"] == expected
def test_invalid():
with pytest.raises(ValueError):
netifaces.ifaddresses("invalid interface")
def test_gateways():
gw = netifaces.gateways()
assert "default" in gw