Address code review comments and fix lint error

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-25 13:36:50 +00:00
parent a46fa50f73
commit b579cb2cce
4 changed files with 66 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
import unittest
from crewai import Agent, Task
@@ -30,3 +31,21 @@ class TestTaskInitFix(unittest.TestCase):
self.assertIsInstance(task.agent, Agent)
self.assertEqual(task.agent.role, "Test Agent")
self.assertIs(task.agent, agent_instance)
def test_task_init_handles_invalid_callable_agent(self):
"""Test that the Task.__init__ method correctly handles invalid callable agents."""
# Create a callable that returns an invalid agent (not an Agent instance)
def invalid_callable_agent():
return "Not an agent"
# Create a task with the invalid callable agent
with self.assertRaises(ValueError) as context:
task = Task(
description="Test Task",
expected_output="Test Output",
agent=invalid_callable_agent
)
# Verify that the error message is correct
self.assertIn("Expected BaseAgent instance", str(context.exception))