fix: add ConfigDict for Pydantic model_config and ClassVar annotations

This commit is contained in:
Greyson LaLonde
2025-09-19 00:44:33 -04:00
parent eca9077590
commit 82cb72ea41
221 changed files with 2365 additions and 2202 deletions

View File

@@ -1,6 +1,7 @@
import pytest
from unittest.mock import MagicMock
import pytest
from crewai.tools import BaseTool, tool
from crewai.tools.tool_usage import ToolUsage
@@ -16,11 +17,11 @@ def test_tool_usage_limit():
return f"Processed {input_text}"
tool = LimitedTool()
result1 = tool.run(input_text="test1")
assert result1 == "Processed test1"
assert tool.current_usage_count == 1
result2 = tool.run(input_text="test2")
assert result2 == "Processed test2"
assert tool.current_usage_count == 2
@@ -36,7 +37,7 @@ def test_unlimited_tool_usage():
return f"Processed {input_text}"
tool = UnlimitedTool()
for i in range(5):
result = tool.run(input_text=f"test{i}")
assert result == f"Processed test{i}"
@@ -49,7 +50,7 @@ def test_tool_decorator_with_usage_limit():
def test_tool(input_text: str) -> str:
"""A test tool."""
return f"Result: {input_text}"
assert test_tool.max_usage_count == 3
assert test_tool.current_usage_count == 0
@@ -64,7 +65,7 @@ def test_default_unlimited_usage():
def default_tool(input_text: str) -> str:
"""A default tool."""
return f"Result: {input_text}"
assert default_tool.max_usage_count is None
assert default_tool.current_usage_count == 0
@@ -77,7 +78,7 @@ def test_invalid_usage_limit():
def _run(self, input_text: str) -> str:
return f"Processed {input_text}"
with pytest.raises(ValueError, match="max_usage_count must be a positive integer"):
ValidTool(max_usage_count=-1)
@@ -93,14 +94,14 @@ def test_reset_usage_count():
return f"Processed {input_text}"
tool = LimitedTool()
tool.run(input_text="test1")
tool.run(input_text="test2")
assert tool.current_usage_count == 2
tool.reset_usage_count()
assert tool.current_usage_count == 0
result = tool.run(input_text="test3")
assert result == "Processed test3"
assert tool.current_usage_count == 1
@@ -117,11 +118,11 @@ def test_tool_usage_with_toolusage_class():
return f"Processed {input_text}"
tool = LimitedTool()
mock_agent = MagicMock()
mock_task = MagicMock()
mock_tools_handler = MagicMock()
tool_usage = ToolUsage(
tools=[tool],
agent=mock_agent,
@@ -129,23 +130,23 @@ def test_tool_usage_with_toolusage_class():
tools_handler=mock_tools_handler,
function_calling_llm=MagicMock(),
)
tool_usage._check_tool_repeated_usage = MagicMock(return_value=False)
tool_usage._format_result = lambda result: result
mock_calling = MagicMock()
mock_calling.tool_name = "Limited Tool"
mock_calling.arguments = {"input_text": "test"}
result1 = tool_usage._check_usage_limit(tool, "Limited Tool")
assert result1 is None
tool.current_usage_count += 1
result2 = tool_usage._check_usage_limit(tool, "Limited Tool")
assert result2 is None
tool.current_usage_count += 1
result3 = tool_usage._check_usage_limit(tool, "Limited Tool")
assert "has reached its usage limit of 2 times" in result3