Skip to content

Commit

Permalink
Added unit tests for Ip6Mask class
Browse files Browse the repository at this point in the history
  • Loading branch information
ccie18643 committed Sep 3, 2024
1 parent f588a0b commit 2a147fd
Show file tree
Hide file tree
Showing 4 changed files with 671 additions and 18 deletions.
3 changes: 1 addition & 2 deletions pytcp/lib/net_addr/ip6_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from __future__ import annotations

import re
import socket
from typing import override

from pytcp.lib.net_addr.ip6_address import IP6__ADDRESS_LEN
Expand Down Expand Up @@ -97,7 +96,7 @@ def __repr__(self) -> str:
Get the IPv6 mask string representation.
"""

return f"{self.__class__.__name__}('{socket.inet_ntop(socket.AF_INET6, bytes(self))}')"
return f"{self.__class__.__name__}('/{len(self)}')"

@override
def __bytes__(self) -> bytes:
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/lib/net_addr/test__ip4_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def setUp(self) -> None:

def test__net_addr__ip4_mask__len(self) -> None:
"""
Ensure the IPv4 address '__len__()' method returns a correct value.
Ensure the IPv4 mask '__len__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -283,7 +283,7 @@ def test__net_addr__ip4_mask__len(self) -> None:

def test__net_addr__ip4_mask__str(self) -> None:
"""
Ensure the IPv4 address '__str__()' method returns a correct value.
Ensure the IPv4 mask '__str__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -293,7 +293,7 @@ def test__net_addr__ip4_mask__str(self) -> None:

def test__net_addr__ip4_mask__repr(self) -> None:
"""
Ensure the IPv4 address '__repr__()' method returns a correct value.
Ensure the IPv4 mask '__repr__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -303,7 +303,7 @@ def test__net_addr__ip4_mask__repr(self) -> None:

def test__net_addr__ip4_mask__bytes(self) -> None:
"""
Ensure the IPv4 address '__bytes__()' method returns a correct value.
Ensure the IPv4 mask '__bytes__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -313,7 +313,7 @@ def test__net_addr__ip4_mask__bytes(self) -> None:

def test__net_addr__ip4_mask__int(self) -> None:
"""
Ensure the IPv4 address '__int__()' method returns a correct value.
Ensure the IPv4 mask '__int__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -323,7 +323,7 @@ def test__net_addr__ip4_mask__int(self) -> None:

def test__net_addr__ip4_mask__eq(self) -> None:
"""
Ensure the IPv4 address '__eq__()' method returns a correct value.
Ensure the IPv4 mask '__eq__()' method returns a correct value.
"""

self.assertTrue(
Expand All @@ -335,12 +335,12 @@ def test__net_addr__ip4_mask__eq(self) -> None:
)

self.assertFalse(
self._ip4_mask == "not an IPv4 address",
self._ip4_mask == "not an IPv4 mask",
)

def test__net_addr__ip4_mask__hash(self) -> None:
"""
Ensure the IPv4 address '__hash__()' method returns a correct value.
Ensure the IPv4 mask '__hash__()' method returns a correct value.
"""

self.assertEqual(
Expand All @@ -350,7 +350,7 @@ def test__net_addr__ip4_mask__hash(self) -> None:

def test__net_addr__ip4_mask__version(self) -> None:
"""
Ensure the IPv4 address 'version' property returns a correct value.
Ensure the IPv4 mask 'version' property returns a correct value.
"""

self.assertEqual(
Expand All @@ -360,7 +360,7 @@ def test__net_addr__ip4_mask__version(self) -> None:

def test__net_addr__ip4_mask__is_ip4(self) -> None:
"""
Ensure the IPv4 address 'is_ip4' property returns a correct
Ensure the IPv4 mask 'is_ip4' property returns a correct
value.
"""

Expand All @@ -371,7 +371,7 @@ def test__net_addr__ip4_mask__is_ip4(self) -> None:

def test__net_addr__ip4_mask__is_ip6(self) -> None:
"""
Ensure the IPv4 address 'is_ip6' property returns a correct
Ensure the IPv4 mask 'is_ip6' property returns a correct
value.
"""

Expand Down Expand Up @@ -447,7 +447,7 @@ def test__net_addr__ip4_mask__is_ip6(self) -> None:
"_results": {
"error": Ip4MaskFormatError,
"error_message": (
"The IPv4 mask format is invalid: Ip6Mask('::')"
"The IPv4 mask format is invalid: Ip6Mask('/0')"
),
},
},
Expand Down
Loading

0 comments on commit 2a147fd

Please sign in to comment.