Fix Black formatting issues in mock toolkit files
This commit is contained in:
parent
0ab8c8fc46
commit
12370845eb
|
|
@ -14,7 +14,7 @@ from tests.unit.graph.mock_toolkit_fix import create_mock_toolkit_with_tools
|
||||||
def test_mock_toolkit_has_all_methods():
|
def test_mock_toolkit_has_all_methods():
|
||||||
"""Test that the mock toolkit has all required methods."""
|
"""Test that the mock toolkit has all required methods."""
|
||||||
toolkit = create_mock_toolkit_with_tools()
|
toolkit = create_mock_toolkit_with_tools()
|
||||||
|
|
||||||
required_methods = [
|
required_methods = [
|
||||||
"get_YFin_data",
|
"get_YFin_data",
|
||||||
"get_YFin_data_online",
|
"get_YFin_data_online",
|
||||||
|
|
@ -23,14 +23,14 @@ def test_mock_toolkit_has_all_methods():
|
||||||
"get_reddit_stock_info",
|
"get_reddit_stock_info",
|
||||||
"get_stock_news_openai",
|
"get_stock_news_openai",
|
||||||
]
|
]
|
||||||
|
|
||||||
for method_name in required_methods:
|
for method_name in required_methods:
|
||||||
assert hasattr(toolkit, method_name), f"Missing {method_name}"
|
assert hasattr(toolkit, method_name), f"Missing {method_name}"
|
||||||
method = getattr(toolkit, method_name)
|
method = getattr(toolkit, method_name)
|
||||||
assert hasattr(method, '__name__'), f"{method_name} missing __name__"
|
assert hasattr(method, "__name__"), f"{method_name} missing __name__"
|
||||||
assert method.__name__ == method_name, f"{method_name} has wrong __name__"
|
assert method.__name__ == method_name, f"{method_name} has wrong __name__"
|
||||||
assert callable(method), f"{method_name} is not callable"
|
assert callable(method), f"{method_name} is not callable"
|
||||||
|
|
||||||
print("✓ Mock toolkit has all required methods with proper attributes")
|
print("✓ Mock toolkit has all required methods with proper attributes")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -40,17 +40,19 @@ def test_tool_node_creation():
|
||||||
# Mock the ToolNode class
|
# Mock the ToolNode class
|
||||||
with patch("langgraph.prebuilt.ToolNode") as MockToolNode:
|
with patch("langgraph.prebuilt.ToolNode") as MockToolNode:
|
||||||
MockToolNode.return_value = Mock()
|
MockToolNode.return_value = Mock()
|
||||||
|
|
||||||
toolkit = create_mock_toolkit_with_tools()
|
toolkit = create_mock_toolkit_with_tools()
|
||||||
|
|
||||||
# Simulate creating tool nodes like in TradingAgentsGraph
|
# Simulate creating tool nodes like in TradingAgentsGraph
|
||||||
from langgraph.prebuilt import ToolNode
|
from langgraph.prebuilt import ToolNode
|
||||||
|
|
||||||
tool_node = ToolNode([
|
tool_node = ToolNode(
|
||||||
toolkit.get_YFin_data,
|
[
|
||||||
toolkit.get_stockstats_indicators_report,
|
toolkit.get_YFin_data,
|
||||||
])
|
toolkit.get_stockstats_indicators_report,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
# Should not raise an error
|
# Should not raise an error
|
||||||
assert MockToolNode.called
|
assert MockToolNode.called
|
||||||
print("✓ ToolNode can be created with mocked toolkit methods")
|
print("✓ ToolNode can be created with mocked toolkit methods")
|
||||||
|
|
@ -60,13 +62,13 @@ def test_tool_node_creation():
|
||||||
def test_tool_decorator():
|
def test_tool_decorator():
|
||||||
"""Test that @tool decorator works with mocked functions."""
|
"""Test that @tool decorator works with mocked functions."""
|
||||||
toolkit = create_mock_toolkit_with_tools()
|
toolkit = create_mock_toolkit_with_tools()
|
||||||
|
|
||||||
# The @tool decorator expects __name__ attribute
|
# The @tool decorator expects __name__ attribute
|
||||||
for attr_name in dir(toolkit):
|
for attr_name in dir(toolkit):
|
||||||
if attr_name.startswith('get_'):
|
if attr_name.startswith("get_"):
|
||||||
method = getattr(toolkit, attr_name)
|
method = getattr(toolkit, attr_name)
|
||||||
assert hasattr(method, '__name__'), f"{attr_name} missing __name__"
|
assert hasattr(method, "__name__"), f"{attr_name} missing __name__"
|
||||||
|
|
||||||
print("✓ All toolkit methods are compatible with @tool decorator")
|
print("✓ All toolkit methods are compatible with @tool decorator")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
@ -74,13 +76,13 @@ def test_tool_decorator():
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Testing mock toolkit fixes for TradingAgentsGraph...")
|
print("Testing mock toolkit fixes for TradingAgentsGraph...")
|
||||||
print("-" * 50)
|
print("-" * 50)
|
||||||
|
|
||||||
tests = [
|
tests = [
|
||||||
test_mock_toolkit_has_all_methods,
|
test_mock_toolkit_has_all_methods,
|
||||||
test_tool_node_creation,
|
test_tool_node_creation,
|
||||||
test_tool_decorator,
|
test_tool_decorator,
|
||||||
]
|
]
|
||||||
|
|
||||||
all_passed = True
|
all_passed = True
|
||||||
for test in tests:
|
for test in tests:
|
||||||
try:
|
try:
|
||||||
|
|
@ -91,10 +93,11 @@ if __name__ == "__main__":
|
||||||
all_passed = False
|
all_passed = False
|
||||||
print(f"✗ {test.__name__} raised exception: {e}")
|
print(f"✗ {test.__name__} raised exception: {e}")
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
print("-" * 50)
|
print("-" * 50)
|
||||||
if all_passed:
|
if all_passed:
|
||||||
print("✅ All tests passed! TradingAgentsGraph mock fixes are working.")
|
print("✅ All tests passed! TradingAgentsGraph mock fixes are working.")
|
||||||
else:
|
else:
|
||||||
print("❌ Some tests failed. Check the output above.")
|
print("❌ Some tests failed. Check the output above.")
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ def create_mock_toolkit_with_tools():
|
||||||
"""Create a mock toolkit with all necessary tool methods."""
|
"""Create a mock toolkit with all necessary tool methods."""
|
||||||
toolkit = Mock()
|
toolkit = Mock()
|
||||||
toolkit.config = {"online_tools": False}
|
toolkit.config = {"online_tools": False}
|
||||||
|
|
||||||
# List of all methods that need to be mocked
|
# List of all methods that need to be mocked
|
||||||
tool_methods = [
|
tool_methods = [
|
||||||
# Market tools
|
# Market tools
|
||||||
|
|
@ -25,25 +25,25 @@ def create_mock_toolkit_with_tools():
|
||||||
"get_reddit_news",
|
"get_reddit_news",
|
||||||
# Fundamentals tools
|
# Fundamentals tools
|
||||||
"get_simfin_cashflow",
|
"get_simfin_cashflow",
|
||||||
"get_simfin_income_stmt",
|
"get_simfin_income_stmt",
|
||||||
"get_simfin_balance_sheet",
|
"get_simfin_balance_sheet",
|
||||||
"get_finnhub_basic_financials",
|
"get_finnhub_basic_financials",
|
||||||
]
|
]
|
||||||
|
|
||||||
# Create mock for each method with proper __name__ attribute
|
# Create mock for each method with proper __name__ attribute
|
||||||
for method_name in tool_methods:
|
for method_name in tool_methods:
|
||||||
# Create a function with the right name
|
# Create a function with the right name
|
||||||
def mock_func():
|
def mock_func():
|
||||||
return f"Mock {method_name} data"
|
return f"Mock {method_name} data"
|
||||||
|
|
||||||
# Create Mock wrapping the function
|
# Create Mock wrapping the function
|
||||||
mock_method = Mock(side_effect=mock_func)
|
mock_method = Mock(side_effect=mock_func)
|
||||||
mock_method.__name__ = method_name
|
mock_method.__name__ = method_name
|
||||||
mock_method.name = method_name
|
mock_method.name = method_name
|
||||||
|
|
||||||
# Set it on the toolkit
|
# Set it on the toolkit
|
||||||
setattr(toolkit, method_name, mock_method)
|
setattr(toolkit, method_name, mock_method)
|
||||||
|
|
||||||
return toolkit
|
return toolkit
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -51,4 +51,4 @@ def patch_toolkit_in_test(mock_toolkit):
|
||||||
"""Configure the mock_toolkit patch to return a properly mocked instance."""
|
"""Configure the mock_toolkit patch to return a properly mocked instance."""
|
||||||
mock_instance = create_mock_toolkit_with_tools()
|
mock_instance = create_mock_toolkit_with_tools()
|
||||||
mock_toolkit.return_value = mock_instance
|
mock_toolkit.return_value = mock_instance
|
||||||
return mock_instance
|
return mock_instance
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue