39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from agent.loop import run_turn
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_run_turn_basic(mock_anthropic_client):
|
|
"""test that run_turn calls the API and returns a message"""
|
|
|
|
# patch the client with our mock
|
|
with patch("agent.loop.client", mock_anthropic_client):
|
|
result = await run_turn("What is 2+2?")
|
|
|
|
# verify client was called
|
|
mock_anthropic_client.messages.create.assert_called_once()
|
|
|
|
# verify message returned
|
|
assert result.content[0].text == "42"
|
|
|
|
# verify call has correct parameters
|
|
call_args = mock_anthropic_client.messages.create.call_args
|
|
assert call_args.kwargs["messages"][0]["content"] == "What is 2+2?"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_run_turn_uses_settings(mock_anthropic_client, settings):
|
|
"""Test that run_turn uses settings correctly."""
|
|
|
|
with patch("agent.loop.client", mock_anthropic_client):
|
|
with patch("agent.loop.settings", settings):
|
|
await run_turn("test message")
|
|
|
|
# Verify settings were used
|
|
call_args = mock_anthropic_client.messages.create.call_args
|
|
assert call_args.kwargs["model"] == settings.model
|
|
assert call_args.kwargs["max_tokens"] == settings.max_tokens
|