fix: Improve mock_toolkit_fix for ToolNode compatibility
- Remove Mock wrapper to provide real functions
- Add __module__ and __doc__ attributes for @tool decorator
- Fixes TypeError: Mock is not a module/class/method/function
🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
55f0b18693
commit
af8863a024
|
|
@ -39,19 +39,20 @@ def create_mock_toolkit_with_tools():
|
||||||
|
|
||||||
mock_func.__name__ = name
|
mock_func.__name__ = name
|
||||||
mock_func.__qualname__ = name
|
mock_func.__qualname__ = name
|
||||||
|
# Add additional attributes that @tool might check
|
||||||
|
mock_func.__module__ = "__main__"
|
||||||
|
mock_func.__doc__ = f"Mock function for {name}"
|
||||||
return mock_func
|
return mock_func
|
||||||
|
|
||||||
# Create the actual function (not a Mock)
|
# Create the actual function (not a Mock)
|
||||||
|
# Use the actual function directly without wrapping in Mock
|
||||||
actual_func = make_mock_func(method_name)
|
actual_func = make_mock_func(method_name)
|
||||||
|
|
||||||
# Wrap it in Mock for test assertions but keep function properties
|
# Add 'name' attribute for tool compatibility
|
||||||
mock_method = Mock(wraps=actual_func)
|
actual_func.name = method_name
|
||||||
mock_method.__name__ = method_name
|
|
||||||
mock_method.__qualname__ = 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, actual_func)
|
||||||
|
|
||||||
return toolkit
|
return toolkit
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue