Add pre commit (#26)

This commit is contained in:
Lamont Huffman
2025-11-05 11:44:19 +08:00
committed by GitHub
parent 2164371e64
commit 30d86efbb3
33 changed files with 565 additions and 496 deletions

View File

@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
import pytest
from unittest.mock import AsyncMock
import pytest
from agentscope.message import Msg
from agentscope.agent import ReActAgent
from agentscope.tool import Toolkit
@@ -12,13 +12,14 @@ class TestReActAgent:
@pytest.fixture
def test_agent(self):
"""Fixture to create a test ReAct agent with fully mocked dependencies"""
"""Fixture to create a test ReAct
agent with fully mocked dependencies"""
async def model_response(*args, **kwargs):
async def model_response():
yield Msg(
name="Friday",
content="Mocked model response",
role="assistant"
role="assistant",
)
mock_model = AsyncMock()
@@ -36,10 +37,12 @@ class TestReActAgent:
model=mock_model,
formatter=mock_formatter,
toolkit=Toolkit(),
memory=mock_memory
memory=mock_memory,
)
# pylint: disable=protected-access
agent._reasoning_hint_msgs = AsyncMock()
# pylint: disable=protected-access
agent._reasoning_hint_msgs.get_memory = AsyncMock(return_value=[])
return agent
@@ -47,16 +50,16 @@ class TestReActAgent:
async def test_exit_command(self, test_agent, monkeypatch):
"""Test exit command handling"""
async def exit_model_response(*args, **kwargs):
async def exit_model_response(*_args, **_kwargs):
yield Msg(
name="Friday",
content="exit",
role="assistant"
role="assistant",
)
test_agent.model.side_effect = exit_model_response
monkeypatch.setattr('builtins.input', lambda _: "exit")
monkeypatch.setattr("builtins.input", lambda _: "exit")
msg = Msg(name="User", content="exit", role="user")
response = await test_agent(msg)
@@ -66,11 +69,13 @@ class TestReActAgent:
async def test_conversation_flow(self, monkeypatch):
"""Test full conversation flow"""
async def model_response(*args, **kwargs):
async def model_response(*_args, **_kwargs):
yield Msg(
name="Friday",
content="Thought: I need to use a tool\nAction: execute_shell_command\nAction Input: echo 'Hello World'",
role="assistant"
content="Thought: I need to use a tool\n"
"Action: execute_shell_command\n"
"Action Input: echo 'Hello World'",
role="assistant",
)
mock_model = AsyncMock()
@@ -88,11 +93,11 @@ class TestReActAgent:
model=mock_model,
formatter=mock_formatter,
toolkit=Toolkit(),
memory=mock_memory
memory=mock_memory,
)
monkeypatch.setattr('builtins.input', lambda _: "Test command")
monkeypatch.setattr("builtins.input", lambda _: "Test command")
msg = Msg(name="User", content="Test command", role="user")
response = await agent(msg)
assert "Thought:" in response.content
assert "Thought:" in response.content