TradingAgents/test_minimal.py

107 lines
2.8 KiB
Python

#!/usr/bin/env python
"""Minimal test to verify mock fixes without problematic imports."""
import sys
from unittest.mock import Mock, patch
import pytest
# Mock the problematic imports
sys.modules['pandas'] = Mock()
sys.modules['yfinance'] = Mock()
sys.modules['openai'] = Mock()
sys.modules['tqdm'] = Mock()
def test_mock_toolkit_structure():
"""Test that mock toolkit has correct structure."""
# Create mock toolkit
toolkit = Mock()
toolkit.config = {"online_tools": False}
# Create proper mock functions
def mock_get_YFin_data():
return "Mock data"
toolkit.get_YFin_data = Mock(side_effect=mock_get_YFin_data)
toolkit.get_YFin_data.__name__ = "get_YFin_data"
toolkit.get_YFin_data.name = "get_YFin_data"
# Test
assert hasattr(toolkit.get_YFin_data, '__name__')
assert toolkit.get_YFin_data.__name__ == "get_YFin_data"
assert callable(toolkit.get_YFin_data)
# Test tool name extraction (what fails in actual tests)
tools = [toolkit.get_YFin_data]
tool_names = [tool.name for tool in tools]
assert "get_YFin_data" in tool_names
print("✓ Mock toolkit structure test passed")
def test_mock_llm_bind_tools():
"""Test that mock LLM can bind tools properly."""
# Create mock LLM
mock_llm = Mock()
mock_chain = Mock()
mock_llm.bind_tools = Mock(return_value=mock_chain)
# Create mock tools
def tool1():
pass
def tool2():
pass
tools = [tool1, tool2]
# Bind tools
result = mock_llm.bind_tools(tools)
# Verify
assert result == mock_chain
mock_llm.bind_tools.assert_called_once_with(tools)
print("✓ Mock LLM bind_tools test passed")
def test_tool_name_extraction():
"""Test various ways of extracting tool names."""
# Method 1: Function with __name__
def func1():
pass
assert hasattr(func1, '__name__')
assert func1.__name__ == 'func1'
# Method 2: Mock with __name__ set
mock_func = Mock()
mock_func.__name__ = 'mock_func'
mock_func.name = 'mock_func'
assert hasattr(mock_func, '__name__')
assert mock_func.__name__ == 'mock_func'
# Method 3: Check both attributes
tools = [func1, mock_func]
names = []
for tool in tools:
if hasattr(tool, 'name'):
names.append(tool.name)
elif hasattr(tool, '__name__'):
names.append(tool.__name__)
assert 'func1' in names
assert 'mock_func' in names
print("✓ Tool name extraction test passed")
if __name__ == "__main__":
print("Running minimal tests...")
print("-" * 40)
test_mock_toolkit_structure()
test_mock_llm_bind_tools()
test_tool_name_extraction()
print("-" * 40)
print("✅ All minimal tests passed!")