diff --git a/src/node_deployer/ip_interface.py b/src/node_deployer/ip_interface.py index dc8ec6e..e5e80d8 100644 --- a/src/node_deployer/ip_interface.py +++ b/src/node_deployer/ip_interface.py @@ -4,37 +4,73 @@ from ipaddress import IPv4Address, IPv6Address, ip_address class IPAddress: def __init__(self, *args, **kwargs) -> None: self.obj: IPv4Address | IPv6Address = ip_address(*args, **kwargs) - to_passthrough = ( - "compressed", - "exploded", - "is_global", - "is_link_local", - "is_loopback", - "is_multicast", - "is_private", - "is_reserved", - "is_unspecified", - "max_prefixlen", - "packed", - "reverse_pointer", - "version", - ) - for attrname in to_passthrough: - self._passthrough(attrname) + # to_passthrough = ( + # "compressed", + # "exploded", + # "is_global", + # "is_link_local", + # "is_loopback", + # "is_multicast", + # "is_private", + # "is_reserved", + # "is_unspecified", + # "max_prefixlen", + # "packed", + # "reverse_pointer", + # "version", + # ) - def _passthrough(self, attrname: str) -> None: - """Passes through an attribute from the underlying IPv4Address or IPv6Address object - - Args: - attrname (str): The name of the attribute to pass through - - Raises: - AttributeError: If the attribute is a method - """ - attr = getattr(self.obj, attrname) - if callable(attr): - raise AttributeError(f"Passthrough is unavailable for methods ({attrname})") - setattr(self, attrname, attr) + @property + def compressed(self) -> str: + return self.obj.compressed + + @property + def exploded(self) -> str: + return self.obj.exploded + + @property + def is_global(self) -> bool: + return self.obj.is_global + + @property + def is_link_local(self) -> bool: + return self.obj.is_link_local + + @property + def is_loopback(self) -> bool: + return self.obj.is_loopback + + @property + def is_multicast(self) -> bool: + return self.obj.is_multicast + + @property + def is_private(self) -> bool: + return self.obj.is_private + + @property + def is_reserved(self) -> bool: + return self.obj.is_reserved + + @property + def is_unspecified(self) -> bool: + return self.obj.is_unspecified + + @property + def max_prefixlen(self) -> int: + return self.obj.max_prefixlen + + @property + def packed(self) -> bytes: + return self.obj.packed + + @property + def reverse_pointer(self) -> str: + return self.obj.reverse_pointer + + @property + def version(self) -> int: + return self.obj.version def __str__(self) -> str: return str(self.obj) diff --git a/tests/test_node_deployer.py b/tests/test_node_deployer.py index 93b55a3..b6c6d8f 100644 --- a/tests/test_node_deployer.py +++ b/tests/test_node_deployer.py @@ -70,11 +70,9 @@ class TestIPInterface: @given(st.ip_addresses(v=4)) def test_ipv4_attr_passthrough(self, ip: IPv4Address): - # Should be able to access all attributes of ipaddress.IPv4Address directly, - # not just a copy of the attribute object at instantiation ip_addr = ip_interface.IPAddress(str(ip)) for attr in self.TEST_ATTRS: - assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr) + assert getattr(ip_addr, attr) == getattr(ip_addr.obj, attr) @given(st.ip_addresses(v=4)) def test_ipv4_bool(self, ip: IPv4Address): @@ -89,11 +87,9 @@ class TestIPInterface: @given(st.ip_addresses(v=6)) def test_ipv6_attr_passthrough(self, ip: IPv6Address): - # Should be able to access all attributes of ipaddress.IPv4Address directly, - # not just a copy of the attribute object at instantiation ip_addr = ip_interface.IPAddress(str(ip)) for attr in self.TEST_ATTRS: - assert getattr(ip_addr, attr) is getattr(ip_addr.obj, attr) + assert getattr(ip_addr, attr) == getattr(ip_addr.obj, attr) @given(st.ip_addresses(v=6)) def test_ipv6_bool(self, ip: IPv6Address):