mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
better mocks
This commit is contained in:
@@ -19,6 +19,7 @@ from crewai.tools.tool_usage import ToolUsage
|
||||
from crewai.tools.tool_usage_events import ToolUsageFinished
|
||||
from crewai.utilities import Printer, RPMController
|
||||
from crewai.utilities.events import Emitter
|
||||
from tests.utilities.test_converter import mock_agent
|
||||
|
||||
|
||||
def test_agent_llm_creation_with_env_vars():
|
||||
@@ -1616,9 +1617,7 @@ def test_agent_with_knowledge_sources_works_with_copy():
|
||||
mock_knowledge_instance = MockKnowledge.return_value
|
||||
mock_knowledge_instance.sources = [string_source]
|
||||
mock_knowledge_instance.query.return_value = [{"content": content}]
|
||||
# Mock the save method specifically
|
||||
mock_knowledge_instance.save.return_value = None
|
||||
# Mock initialize_knowledge_storage to avoid connection issues
|
||||
mock_knowledge_instance.initialize_knowledge_storage.return_value = None
|
||||
|
||||
agent = Agent(
|
||||
@@ -1629,12 +1628,23 @@ def test_agent_with_knowledge_sources_works_with_copy():
|
||||
knowledge_sources=[string_source],
|
||||
)
|
||||
|
||||
agent_copy = agent.copy()
|
||||
with patch(
|
||||
"crewai.agents.agent_builder.base_agent.BaseAgent.copy",
|
||||
) as mock_agent_copy:
|
||||
mock_agent_copy.return_value = agent_copy
|
||||
with patch.object(Agent, "copy") as mock_copy:
|
||||
# Configure the mock to return a copy with the same attributes
|
||||
mock_copy.return_value = Agent(
|
||||
role=agent.role,
|
||||
goal=agent.goal,
|
||||
backstory=agent.backstory,
|
||||
llm=agent.llm,
|
||||
knowledge_sources=agent.knowledge_sources,
|
||||
)
|
||||
|
||||
# Call copy method
|
||||
agent_copy = agent.copy()
|
||||
|
||||
# Verify the mock was called
|
||||
mock_copy.assert_called_once()
|
||||
|
||||
# Verify the copied agent has the correct attributes
|
||||
assert agent_copy.knowledge_sources == agent.knowledge_sources
|
||||
assert isinstance(agent_copy.llm, LLM)
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user