Formatting

This commit is contained in:
2025-12-07 03:33:51 +01:00
parent a923a760ef
commit 4eae1d6d58
24 changed files with 1003 additions and 833 deletions

View File

@@ -1,16 +1,13 @@
"""Pytest configuration and shared fixtures."""
import pytest
import tempfile
import shutil
from pathlib import Path
from unittest.mock import Mock, MagicMock
from infrastructure.persistence import Memory, init_memory, set_memory, get_memory
from infrastructure.persistence.memory import (
LongTermMemory,
ShortTermMemory,
EpisodicMemory,
)
import shutil
import tempfile
from pathlib import Path
from unittest.mock import MagicMock, Mock
import pytest
from infrastructure.persistence import Memory, set_memory
@pytest.fixture
@@ -122,12 +119,11 @@ def memory_with_library(memory):
def mock_llm():
"""Create a mock LLM client that returns OpenAI-compatible format."""
llm = Mock()
# Return OpenAI-style message dict without tool calls
def complete_func(messages, tools=None):
return {
"role": "assistant",
"content": "I found what you're looking for!"
}
return {"role": "assistant", "content": "I found what you're looking for!"}
llm.complete = Mock(side_effect=complete_func)
return llm
@@ -136,34 +132,33 @@ def mock_llm():
def mock_llm_with_tool_call():
"""Create a mock LLM that returns a tool call then a response."""
llm = Mock()
# First call returns a tool call, second returns final response
def complete_side_effect(messages, tools=None):
if not hasattr(complete_side_effect, 'call_count'):
if not hasattr(complete_side_effect, "call_count"):
complete_side_effect.call_count = 0
complete_side_effect.call_count += 1
if complete_side_effect.call_count == 1:
# First call: return tool call
return {
"role": "assistant",
"content": None,
"tool_calls": [{
"id": "call_123",
"type": "function",
"function": {
"name": "find_torrent",
"arguments": '{"media_title": "Inception"}'
"tool_calls": [
{
"id": "call_123",
"type": "function",
"function": {
"name": "find_torrent",
"arguments": '{"media_title": "Inception"}',
},
}
}]
],
}
else:
# Second call: return final response
return {
"role": "assistant",
"content": "I found 3 torrents for Inception!"
}
return {"role": "assistant", "content": "I found 3 torrents for Inception!"}
llm.complete = Mock(side_effect=complete_side_effect)
return llm
@@ -248,36 +243,36 @@ def mock_deepseek():
"""
Mock DeepSeekClient for individual tests that need it.
This prevents real API calls in tests that use this fixture.
Usage:
def test_something(mock_deepseek):
# Your test code here
"""
import sys
from unittest.mock import Mock, MagicMock
from unittest.mock import Mock
# Save the original module if it exists
original_module = sys.modules.get('agent.llm.deepseek')
original_module = sys.modules.get("agent.llm.deepseek")
# Create a mock module for deepseek
mock_deepseek_module = MagicMock()
class MockDeepSeekClient:
def __init__(self, *args, **kwargs):
self.complete = Mock(return_value="Mocked LLM response")
mock_deepseek_module.DeepSeekClient = MockDeepSeekClient
# Inject the mock
sys.modules['agent.llm.deepseek'] = mock_deepseek_module
sys.modules["agent.llm.deepseek"] = mock_deepseek_module
yield mock_deepseek_module
# Restore the original module
if original_module is not None:
sys.modules['agent.llm.deepseek'] = original_module
elif 'agent.llm.deepseek' in sys.modules:
del sys.modules['agent.llm.deepseek']
sys.modules["agent.llm.deepseek"] = original_module
elif "agent.llm.deepseek" in sys.modules:
del sys.modules["agent.llm.deepseek"]
@pytest.fixture
@@ -287,8 +282,8 @@ def mock_agent_step():
Returns a context manager that patches app.agent.step.
"""
from unittest.mock import patch
def _mock_step(return_value="Mocked agent response"):
return patch("app.agent.step", return_value=return_value)
return _mock_step