mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-11 00:58:30 +00:00
Trying to fix tests
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
from unittest.mock import MagicMock
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from crewai import Agent, Task
|
from crewai import Agent
|
||||||
from crewai.tools.agent_tools.base_agent_tools import BaseAgentTool
|
from crewai.tools.agent_tools.base_agent_tools import BaseAgentTool
|
||||||
|
|
||||||
|
|
||||||
@@ -14,9 +12,8 @@ class InternalAgentTool(BaseAgentTool):
|
|||||||
return "Test response"
|
return "Test response"
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
def test_agent_tool_role_matching():
|
||||||
"role_name,should_match",
|
test_cases = [
|
||||||
[
|
|
||||||
("Futel Official Infopoint", True), # exact match
|
("Futel Official Infopoint", True), # exact match
|
||||||
(' "Futel Official Infopoint" ', True), # extra quotes and spaces
|
(' "Futel Official Infopoint" ', True), # extra quotes and spaces
|
||||||
("Futel Official Infopoint\n", True), # trailing newline
|
("Futel Official Infopoint\n", True), # trailing newline
|
||||||
@@ -26,31 +23,30 @@ class InternalAgentTool(BaseAgentTool):
|
|||||||
("FUTEL OFFICIAL INFOPOINT", True), # uppercase
|
("FUTEL OFFICIAL INFOPOINT", True), # uppercase
|
||||||
("Non Existent Agent", False), # non-existent agent
|
("Non Existent Agent", False), # non-existent agent
|
||||||
(None, False), # None agent name
|
(None, False), # None agent name
|
||||||
],
|
]
|
||||||
)
|
|
||||||
def test_agent_tool_role_matching(role_name, should_match):
|
|
||||||
"""Test that agent tools can match roles regardless of case, whitespace, and special characters."""
|
|
||||||
# Create test agent
|
|
||||||
test_agent = Agent(
|
|
||||||
role="Futel Official Infopoint",
|
|
||||||
goal="Answer questions about Futel",
|
|
||||||
backstory="Futel Football Club info",
|
|
||||||
allow_delegation=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Create test agent tool
|
for role_name, should_match in test_cases:
|
||||||
agent_tool = InternalAgentTool(
|
# Setup your test agent and agent tool
|
||||||
name="test_tool", description="Test tool", agents=[test_agent]
|
test_agent = Agent(
|
||||||
)
|
role="Futel Official Infopoint",
|
||||||
|
goal="Answer questions about Futel",
|
||||||
|
backstory="Futel Football Club info",
|
||||||
|
allow_delegation=False,
|
||||||
|
)
|
||||||
|
agent_tool = InternalAgentTool(
|
||||||
|
name="test_tool", description="Test tool", agents=[test_agent]
|
||||||
|
)
|
||||||
|
|
||||||
# Test role matching
|
# Execute the test using _execute
|
||||||
result = agent_tool._execute(agent_name=role_name, task="Test task", context=None)
|
result = agent_tool._execute(
|
||||||
|
agent_name=role_name, task="Test task", context=None
|
||||||
|
)
|
||||||
|
|
||||||
if should_match:
|
if should_match:
|
||||||
assert (
|
assert (
|
||||||
"coworker mentioned not found" not in result.lower()
|
"coworker mentioned not found" not in result.lower()
|
||||||
), f"Should find agent with role name: {role_name}"
|
), f"Should find agent with role name: {role_name}"
|
||||||
else:
|
else:
|
||||||
assert (
|
assert (
|
||||||
"coworker mentioned not found" in result.lower()
|
"coworker mentioned not found" in result.lower()
|
||||||
), f"Should not find agent with role name: {role_name}"
|
), f"Should not find agent with role name: {role_name}"
|
||||||
|
|||||||
Reference in New Issue
Block a user