mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
feat: add fixed time to fix test
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
"""Test Agent creation and execution basic functionality."""
|
"""Test Agent creation and execution basic functionality."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from datetime import UTC, datetime, timezone
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
@@ -908,6 +909,8 @@ def test_tool_result_as_answer_is_the_final_answer_for_the_agent():
|
|||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
def test_tool_usage_information_is_appended_to_agent():
|
def test_tool_usage_information_is_appended_to_agent():
|
||||||
|
from datetime import UTC, datetime
|
||||||
|
|
||||||
from crewai.tools import BaseTool
|
from crewai.tools import BaseTool
|
||||||
|
|
||||||
class MyCustomTool(BaseTool):
|
class MyCustomTool(BaseTool):
|
||||||
@@ -917,30 +920,36 @@ def test_tool_usage_information_is_appended_to_agent():
|
|||||||
def _run(self) -> str:
|
def _run(self) -> str:
|
||||||
return "Howdy!"
|
return "Howdy!"
|
||||||
|
|
||||||
agent1 = Agent(
|
fixed_datetime = datetime(2025, 2, 10, 12, 0, 0, tzinfo=UTC)
|
||||||
role="Friendly Neighbor",
|
with patch("crewai.tools.tool_usage.datetime") as mock_datetime:
|
||||||
goal="Make everyone feel welcome",
|
mock_datetime.now.return_value = fixed_datetime
|
||||||
backstory="You are the friendly neighbor",
|
mock_datetime.UTC = UTC
|
||||||
tools=[MyCustomTool(result_as_answer=True)],
|
|
||||||
)
|
|
||||||
|
|
||||||
greeting = Task(
|
agent1 = Agent(
|
||||||
description="Say an appropriate greeting.",
|
role="Friendly Neighbor",
|
||||||
expected_output="The greeting.",
|
goal="Make everyone feel welcome",
|
||||||
agent=agent1,
|
backstory="You are the friendly neighbor",
|
||||||
)
|
tools=[MyCustomTool(result_as_answer=True)],
|
||||||
tasks = [greeting]
|
)
|
||||||
crew = Crew(agents=[agent1], tasks=tasks)
|
|
||||||
|
|
||||||
crew.kickoff()
|
greeting = Task(
|
||||||
assert agent1.tools_results == [
|
description="Say an appropriate greeting.",
|
||||||
{
|
expected_output="The greeting.",
|
||||||
"result": "Howdy!",
|
agent=agent1,
|
||||||
"tool_name": "Decide Greetings",
|
)
|
||||||
"tool_args": {},
|
tasks = [greeting]
|
||||||
"result_as_answer": True,
|
crew = Crew(agents=[agent1], tasks=tasks)
|
||||||
}
|
|
||||||
]
|
crew.kickoff()
|
||||||
|
assert agent1.tools_results == [
|
||||||
|
{
|
||||||
|
"result": "Howdy!",
|
||||||
|
"tool_name": "Decide Greetings",
|
||||||
|
"tool_args": {},
|
||||||
|
"result_as_answer": True,
|
||||||
|
"start_time": fixed_datetime,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_agent_definition_based_on_dict():
|
def test_agent_definition_based_on_dict():
|
||||||
|
|||||||
Reference in New Issue
Block a user