mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-04 01:57:25 -04:00
feat: add LangChain-compatible mock chat model wrapper
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import pytest
|
||||
import asyncio
|
||||
from agent.mock_provider.mock_ai_provider import MockAIProvider
|
||||
from agent.mock_provider.mock_langchain_model import MockChatModel
|
||||
|
||||
|
||||
def test_mock_provider_rotates_stocks():
|
||||
@@ -32,3 +34,41 @@ def test_mock_provider_valid_json_tool_calls():
|
||||
provider = MockAIProvider()
|
||||
response = provider.generate_response("2025-01-01", step=0)
|
||||
assert "[calls tool_get_price" in response or "get_price" in response.lower()
|
||||
|
||||
|
||||
def test_mock_chat_model_invoke():
|
||||
"""Test synchronous invoke returns proper message format"""
|
||||
model = MockChatModel(date="2025-01-01")
|
||||
|
||||
messages = [{"role": "user", "content": "Analyze the market"}]
|
||||
response = model.invoke(messages)
|
||||
|
||||
assert hasattr(response, "content")
|
||||
assert "AAPL" in response.content
|
||||
assert "<FINISH_SIGNAL>" in response.content
|
||||
|
||||
|
||||
def test_mock_chat_model_ainvoke():
|
||||
"""Test asynchronous invoke returns proper message format"""
|
||||
async def run_test():
|
||||
model = MockChatModel(date="2025-01-02")
|
||||
messages = [{"role": "user", "content": "Analyze the market"}]
|
||||
response = await model.ainvoke(messages)
|
||||
|
||||
assert hasattr(response, "content")
|
||||
assert "MSFT" in response.content
|
||||
assert "<FINISH_SIGNAL>" in response.content
|
||||
|
||||
asyncio.run(run_test())
|
||||
|
||||
|
||||
def test_mock_chat_model_different_dates():
|
||||
"""Test that different dates produce different responses"""
|
||||
model1 = MockChatModel(date="2025-01-01")
|
||||
model2 = MockChatModel(date="2025-01-02")
|
||||
|
||||
msg = [{"role": "user", "content": "Trade"}]
|
||||
response1 = model1.invoke(msg)
|
||||
response2 = model2.invoke(msg)
|
||||
|
||||
assert response1.content != response2.content
|
||||
|
||||
Reference in New Issue
Block a user