🐫 CAMEL: The first and the best multi-agent framework. Finding the Scaling Law of Agents. https://www.camel-ai.org
Python agentai-societiesartificial-intelligencecommunicative-aicooperative-aideep-learninglarge-language-modelsmulti-agent-systemsnatural-language-processing
chore: MagicMock in test_workforce_single_agent.py (#3135)
Wendong-Fance8e504afeec
diff --git a/camel/environments/tic_tac_toe.py b/camel/environments/tic_tac_toe.pyindex be6f17896..afb81add3 100644--- a/camel/environments/tic_tac_toe.py+++ b/camel/environments/tic_tac_toe.py@@ -483,7 +483,7 @@ class TicTacToeEnv(MultiStepEnv):# Check all win combinations.for a, b, c in TicTacToeEnv.WIN_COMBINATIONS:if board[a] != " " and board[a] == board[b] == board[c]:- return board[a]+ return board[a] # type: ignore[return-value]# Check for draw.if all(cell != " " for cell in board):return "draw"diff --git a/test/workforce/test_workforce_single_agent.py b/test/workforce/test_workforce_single_agent.pyindex 54766df8b..66bc8542f 100644--- a/test/workforce/test_workforce_single_agent.py+++ b/test/workforce/test_workforce_single_agent.py@@ -13,6 +13,7 @@# ========= Copyright 2023-2024 @ CAMEL-AI.org. All Rights Reserved. =========import timefrom typing import List+from unittest.mock import patchimport pytest@@ -102,7 +103,11 @@ async def test_graceful_shutdown_one_second_timeout():@pytest.mark.asyncio-async def test_get_dep_tasks_info():+@patch('camel.tasks.task.Task.decompose')+@patch(+ 'camel.societies.workforce.single_agent_worker.SingleAgentWorker._process_task'+)+async def test_get_dep_tasks_info(mock_process_task, mock_decompose):"""Original test for backwards compatibility."""sys_msg = BaseMessage.make_assistant_message(role_name="programmer",@@ -115,7 +120,18 @@ async def test_get_dep_tasks_info():id='0',)- subtasks = human_task.decompose(agent) # TODO: use MagicMock- await test_worker._process_task(- human_task, subtasks- ) # TODO: use MagicMock+ # Configure the mocks+ mock_subtasks = [+ Task(content="Task 1", id="1"),+ Task(content="Task 2", id="2"),+ ]+ mock_decompose.return_value = mock_subtasks+ mock_process_task.return_value = TaskState.DONE++ # Execute the test+ subtasks = human_task.decompose(agent)+ await test_worker._process_task(human_task, subtasks)++ # Verify the mocks were called+ mock_decompose.assert_called_once_with(agent)+ mock_process_task.assert_called_once_with(human_task, mock_subtasks)