Apply automatic linting fixes to tests directory

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-05-12 13:31:07 +00:00
parent ad1ea46bbb
commit 46621113af
62 changed files with 1738 additions and 1821 deletions

View File

@@ -8,28 +8,27 @@ from crewai.memory.user.user_memory_item import UserMemoryItem
class MockCrew:
def __init__(self, memory_config):
def __init__(self, memory_config) -> None:
self.memory_config = memory_config
@pytest.fixture
def user_memory():
"""Fixture to create a UserMemory instance"""
"""Fixture to create a UserMemory instance."""
crew = MockCrew(
memory_config={
"provider": "mem0",
"config": {"user_id": "john"},
"user_memory" : {}
}
"user_memory" : {},
},
)
user_memory = MagicMock(spec=UserMemory)
with patch.object(Memory,'__new__',return_value=user_memory):
user_memory_instance = UserMemory(crew=crew)
return user_memory_instance
with patch.object(Memory,"__new__",return_value=user_memory):
return UserMemory(crew=crew)
def test_save_and_search(user_memory):
def test_save_and_search(user_memory) -> None:
memory = UserMemoryItem(
data="""test value test value test value test value test value test value
test value test value test value test value test value test value
@@ -42,13 +41,13 @@ def test_save_and_search(user_memory):
user_memory.save(
value=memory.data,
metadata=memory.metadata,
user=memory.user
user=memory.user,
)
mock_save.assert_called_once_with(
value=memory.data,
metadata=memory.metadata,
user=memory.user
user=memory.user,
)
expected_result = [
@@ -56,12 +55,12 @@ def test_save_and_search(user_memory):
"context": memory.data,
"metadata": {"agent": "test_agent"},
"score": 0.95,
}
},
]
expected_result = ["mocked_result"]
# Use patch.object to mock UserMemory's search method
with patch.object(UserMemory, 'search', return_value=expected_result) as mock_search:
with patch.object(UserMemory, "search", return_value=expected_result) as mock_search:
find = UserMemory.search("test value", score_threshold=0.01)[0]
mock_search.assert_called_once_with("test value", score_threshold=0.01)
assert find == expected_result[0]