mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Address PR feedback: improve documentation, add deprecation warning, enhance test coverage
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import asyncio
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import uuid
|
||||
import warnings
|
||||
from concurrent.futures import Future
|
||||
from copy import copy as shallow_copy
|
||||
from hashlib import md5
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, Union, cast
|
||||
from typing import Any, Callable, Dict, List, Optional, Set, Tuple, TypeAlias, Union, cast
|
||||
|
||||
from pydantic import (
|
||||
UUID4,
|
||||
@@ -1386,4 +1387,16 @@ class Crew(BaseModel):
|
||||
raise RuntimeError(f"Failed to reset {name} memory") from e
|
||||
|
||||
|
||||
Crewai = Crew
|
||||
def _get_crewai():
|
||||
warnings.warn(
|
||||
"Crewai is deprecated, use Crew instead.",
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return Crew
|
||||
|
||||
class _CrewaiDescriptor:
|
||||
def __get__(self, obj, objtype=None):
|
||||
return _get_crewai()
|
||||
|
||||
sys.modules[__name__].__dict__['Crewai'] = _get_crewai()
|
||||
|
||||
@@ -1,17 +1,56 @@
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCrewaiAlias(unittest.TestCase):
|
||||
"""Test the Crewai alias for backward compatibility."""
|
||||
"""Tests validating the Crewai alias and its backward compatibility.
|
||||
|
||||
These tests ensure that the Crewai alias works correctly for both
|
||||
import scenarios and practical usage, providing backward compatibility
|
||||
for existing code that uses the 'Crewai' name.
|
||||
"""
|
||||
|
||||
def test_crewai_alias_import(self):
|
||||
"""Test that Crewai can be imported from crewai.crew."""
|
||||
try:
|
||||
from crewai.crew import Crewai
|
||||
from crewai.crew import Crew
|
||||
from crewai.crew import Crew, Crewai
|
||||
|
||||
self.assertEqual(Crewai, Crew)
|
||||
except ImportError:
|
||||
self.fail("Failed to import Crewai from crewai.crew")
|
||||
|
||||
def test_crewai_instance_creation(self):
|
||||
"""Ensure Crewai can be instantiated just like Crew."""
|
||||
from crewai.crew import Crew, Crewai
|
||||
from crewai.agent import Agent
|
||||
|
||||
test_agent = Agent(
|
||||
role="Test Agent",
|
||||
goal="Testing",
|
||||
backstory="Created for testing"
|
||||
)
|
||||
|
||||
crewai_instance = Crewai(agents=[test_agent], tasks=[])
|
||||
crew_instance = Crew(agents=[test_agent], tasks=[])
|
||||
|
||||
self.assertIsInstance(crewai_instance, Crew)
|
||||
self.assertEqual(type(crewai_instance), type(crew_instance))
|
||||
|
||||
def test_crewai_deprecation_warning(self):
|
||||
"""Test that using Crewai emits a deprecation warning."""
|
||||
import warnings
|
||||
import importlib
|
||||
import crewai.crew
|
||||
|
||||
with warnings.catch_warnings(record=True) as w:
|
||||
warnings.simplefilter("always")
|
||||
importlib.reload(crewai.crew)
|
||||
|
||||
self.assertTrue(len(w) > 0, "No deprecation warning was captured")
|
||||
self.assertTrue(any(issubclass(warning.category, DeprecationWarning) for warning in w),
|
||||
"No DeprecationWarning was found")
|
||||
self.assertTrue(any("Crewai is deprecated" in str(warning.message) for warning in w),
|
||||
"Warning message doesn't contain expected text")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user