Unfucked gemini's mess
This commit is contained in:
@@ -120,9 +120,15 @@ def memory_with_library(memory):
|
||||
|
||||
@pytest.fixture
|
||||
def mock_llm():
|
||||
"""Create a mock LLM client."""
|
||||
"""Create a mock LLM client that returns OpenAI-compatible format."""
|
||||
llm = Mock()
|
||||
llm.complete = Mock(return_value="I found what you're looking for!")
|
||||
# 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!"
|
||||
}
|
||||
llm.complete = Mock(side_effect=complete_func)
|
||||
return llm
|
||||
|
||||
|
||||
@@ -130,12 +136,35 @@ def mock_llm():
|
||||
def mock_llm_with_tool_call():
|
||||
"""Create a mock LLM that returns a tool call then a response."""
|
||||
llm = Mock()
|
||||
llm.complete = Mock(
|
||||
side_effect=[
|
||||
'{"thought": "Searching", "action": {"name": "find_torrents", "args": {"media_title": "Inception"}}}',
|
||||
"I found 3 torrents for Inception!",
|
||||
]
|
||||
)
|
||||
|
||||
# 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'):
|
||||
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"}'
|
||||
}
|
||||
}]
|
||||
}
|
||||
else:
|
||||
# Second call: return final response
|
||||
return {
|
||||
"role": "assistant",
|
||||
"content": "I found 3 torrents for Inception!"
|
||||
}
|
||||
|
||||
llm.complete = Mock(side_effect=complete_side_effect)
|
||||
return llm
|
||||
|
||||
|
||||
@@ -214,15 +243,22 @@ def real_folder(temp_dir):
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture(scope="session", autouse=True)
|
||||
def mock_deepseek_globally():
|
||||
@pytest.fixture(scope="function")
|
||||
def mock_deepseek():
|
||||
"""
|
||||
Mock DeepSeekClient globally before any imports happen.
|
||||
This prevents real API calls in all tests.
|
||||
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
|
||||
|
||||
# Save the original module if it exists
|
||||
original_module = sys.modules.get('agent.llm.deepseek')
|
||||
|
||||
# Create a mock module for deepseek
|
||||
mock_deepseek_module = MagicMock()
|
||||
|
||||
@@ -232,13 +268,15 @@ def mock_deepseek_globally():
|
||||
|
||||
mock_deepseek_module.DeepSeekClient = MockDeepSeekClient
|
||||
|
||||
# Inject the mock before the real module is imported
|
||||
# Inject the mock
|
||||
sys.modules['agent.llm.deepseek'] = mock_deepseek_module
|
||||
|
||||
yield
|
||||
yield mock_deepseek_module
|
||||
|
||||
# Cleanup (optional, but good practice)
|
||||
if 'agent.llm.deepseek' in sys.modules:
|
||||
# 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']
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user