fix: ruff checks is now in order:)

ref: N25B-205
This commit is contained in:
Björn Otgaar
2025-10-30 16:41:35 +01:00
parent af3e4ae56a
commit 30453be4b2
10 changed files with 117 additions and 84 deletions

View File

@@ -1,6 +1,8 @@
import asyncio
from unittest.mock import ANY, AsyncMock, MagicMock, patch
import pytest
from unittest.mock import AsyncMock, MagicMock, patch, ANY
from control_backend.agents.ri_communication_agent import RICommunicationAgent
@@ -109,7 +111,11 @@ async def test_setup_creates_socket_and_negotiate_1(monkeypatch):
# --- Act ---
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
@@ -153,7 +159,11 @@ async def test_setup_creates_socket_and_negotiate_2(monkeypatch):
# --- Act ---
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
@@ -189,8 +199,8 @@ async def test_setup_creates_socket_and_negotiate_3(monkeypatch, caplog):
# Mock RICommandAgent agent startup
# We are sending wrong negotiation info to the communication agent, so we should retry and expect a
# better response, within a limited time.
# We are sending wrong negotiation info to the communication agent,
# so we should retry and expect a better response, within a limited time.
with patch(
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
) as MockCommandAgent:
@@ -200,7 +210,11 @@ async def test_setup_creates_socket_and_negotiate_3(monkeypatch, caplog):
# --- Act ---
with caplog.at_level("ERROR"):
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
@@ -240,7 +254,11 @@ async def test_setup_creates_socket_and_negotiate_4(monkeypatch):
fake_pub_socket = AsyncMock()
# --- Act ---
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=True
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=True,
)
await agent.setup()
@@ -283,7 +301,11 @@ async def test_setup_creates_socket_and_negotiate_5(monkeypatch):
fake_pub_socket = AsyncMock()
# --- Act ---
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
@@ -326,7 +348,11 @@ async def test_setup_creates_socket_and_negotiate_6(monkeypatch):
fake_pub_socket = AsyncMock()
# --- Act ---
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup()
@@ -362,8 +388,8 @@ async def test_setup_creates_socket_and_negotiate_7(monkeypatch, caplog):
# Mock RICommandAgent agent startup
# We are sending wrong negotiation info to the communication agent, so we should retry and expect a
# better response, within a limited time.
# We are sending wrong negotiation info to the communication agent,
# so we should retry and expect a etter response, within a limited time.
with patch(
"control_backend.agents.ri_communication_agent.RICommandAgent", autospec=True
) as MockCommandAgent:
@@ -374,7 +400,11 @@ async def test_setup_creates_socket_and_negotiate_7(monkeypatch, caplog):
# --- Act ---
with caplog.at_level("WARNING"):
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
@@ -408,11 +438,15 @@ async def test_setup_creates_socket_and_negotiate_timeout(monkeypatch, caplog):
fake_agent_instance = MockCommandAgent.return_value
fake_agent_instance.start = AsyncMock()
fake_pub_socket = AsyncMock()
# --- Act ---
with caplog.at_level("WARNING"):
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
await agent.setup(max_retries=1)
@@ -544,13 +578,16 @@ async def test_setup_unexpected_exception(monkeypatch, caplog):
# Simulate unexpected exception during recv_json()
fake_socket.recv_json = AsyncMock(side_effect=Exception("boom!"))
monkeypatch.setattr(
"control_backend.agents.ri_communication_agent.context.socket", lambda _: fake_socket
)
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
with caplog.at_level("ERROR"):
@@ -587,7 +624,11 @@ async def test_setup_unpacking_exception(monkeypatch, caplog):
fake_pub_socket = AsyncMock()
agent = RICommunicationAgent(
"test@server", "password", pub_socket=fake_pub_socket, address="tcp://localhost:5555", bind=False
"test@server",
"password",
pub_socket=fake_pub_socket,
address="tcp://localhost:5555",
bind=False,
)
# --- Act & Assert ---