Skip to content

Commit 224f841

Browse files
committed
feat(core/tests): add TestSocketPort test (#6)
Signed-off-by: Ronan Abhamon <ronan.abhamon@vates.tech>
1 parent 2c8cc00 commit 224f841

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

‎tests/network/test_socket.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
format_address,
3131
get_ip_address,
3232
get_socket_family_str,
33+
get_socket_port,
3334
Socket,
3435
socket_receive,
3536
socket_send,
@@ -204,6 +205,20 @@ def test_get_socket_family_str(
204205

205206
# ------------------------------------------------------------------------------
206207

208+
class TestSocketPort:
209+
def test_get_socket_port(self) -> None:
210+
with socket.socket() as sock:
211+
sock.bind(("127.0.0.1", 0))
212+
port = get_socket_port(sock)
213+
assert port is not None and port > 0
214+
215+
def test_get_socket_port_closed_socket(self) -> None:
216+
with socket.socket() as sock:
217+
sock.close()
218+
assert get_socket_port(sock) is None
219+
220+
# ------------------------------------------------------------------------------
221+
207222
@pytest.fixture
208223
def mock_sock() -> MagicMock:
209224
return MagicMock(spec=socket.socket)

0 commit comments

Comments
 (0)