Skip to content

Commit ce8e504

Browse files
authored
chore: MagicMock in test_workforce_single_agent.py (#3135)
1 parent 24fa71f commit ce8e504

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

camel/environments/tic_tac_toe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ def check_winner(board: List[str]) -> Optional[Literal["X", "O", "draw"]]:
483483
# Check all win combinations.
484484
for a, b, c in TicTacToeEnv.WIN_COMBINATIONS:
485485
if board[a] != " " and board[a] == board[b] == board[c]:
486-
return board[a]
486+
return board[a] # type: ignore[return-value]
487487
# Check for draw.
488488
if all(cell != " " for cell in board):
489489
return "draw"

test/workforce/test_workforce_single_agent.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========
1414
import time
1515
from typing import List
16+
from unittest.mock import patch
1617

1718
import pytest
1819

@@ -102,7 +103,11 @@ async def test_graceful_shutdown_one_second_timeout():
102103

103104

104105
@pytest.mark.asyncio
105-
async def test_get_dep_tasks_info():
106+
@patch('camel.tasks.task.Task.decompose')
107+
@patch(
108+
'camel.societies.workforce.single_agent_worker.SingleAgentWorker._process_task'
109+
)
110+
async def test_get_dep_tasks_info(mock_process_task, mock_decompose):
106111
"""Original test for backwards compatibility."""
107112
sys_msg = BaseMessage.make_assistant_message(
108113
role_name="programmer",
@@ -115,7 +120,18 @@ async def test_get_dep_tasks_info():
115120
id='0',
116121
)
117122

118-
subtasks = human_task.decompose(agent) # TODO: use MagicMock
119-
await test_worker._process_task(
120-
human_task, subtasks
121-
) # TODO: use MagicMock
123+
# Configure the mocks
124+
mock_subtasks = [
125+
Task(content="Task 1", id="1"),
126+
Task(content="Task 2", id="2"),
127+
]
128+
mock_decompose.return_value = mock_subtasks
129+
mock_process_task.return_value = TaskState.DONE
130+
131+
# Execute the test
132+
subtasks = human_task.decompose(agent)
133+
await test_worker._process_task(human_task, subtasks)
134+
135+
# Verify the mocks were called
136+
mock_decompose.assert_called_once_with(agent)
137+
mock_process_task.assert_called_once_with(human_task, mock_subtasks)

0 commit comments

Comments
 (0)