From d6b7cc3dfae38e708b074b179187cf4ce4de3478 Mon Sep 17 00:00:00 2001 From: DipayanDasgupta Date: Fri, 3 Oct 2025 08:56:22 +0000 Subject: [PATCH] test(reasoning): Add tests for Reasoning base class --- tests/test_reasoning/test_reasoning.py | 53 +++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/tests/test_reasoning/test_reasoning.py b/tests/test_reasoning/test_reasoning.py index 878602d..f654be3 100644 --- a/tests/test_reasoning/test_reasoning.py +++ b/tests/test_reasoning/test_reasoning.py @@ -1,10 +1,9 @@ -# tests/test_reasoning/test_reasoning.py - from unittest.mock import Mock from mesa_llm.reasoning.reasoning import ( Observation, Plan, + Reasoning, ) @@ -39,3 +38,53 @@ def test_plan_creation(self): assert plan.step == 1 assert plan.llm_plan == mock_llm_response assert plan.ttl == 3 + + +class TestReasoningBase: + """Tests for the abstract Reasoning base class.""" + + def test_execute_tool_call_generates_plan(self): + """Test that the base execute_tool_call method produces a Plan.""" + # 1. Setup a mock agent with all necessary components + mock_agent = Mock() + mock_agent.model.steps = 5 + + # Mock the LLM and its response + mock_llm_response = Mock() + mock_llm_response.choices = [Mock()] + mock_llm_response.choices[0].message = "Final LLM message" + mock_agent.llm.generate.return_value = mock_llm_response + + # Mock the Tool Manager + mock_agent.tool_manager.get_all_tools_schema.return_value = [ + {"schema": "example"} + ] + + # 2. Instantiate a concrete implementation of Reasoning to test the base method + class ConcreteReasoning(Reasoning): + def plan(self, prompt, obs=None, ttl=1, selected_tools=None): + pass # Not needed for this test + + reasoning = ConcreteReasoning(agent=mock_agent) + + # 3. Call the method we want to test + chaining_message = "Execute the plan." + result_plan = reasoning.execute_tool_call( + chaining_message, selected_tools=["tool1"] + ) + + # 4. Assert the results + # Assert that the LLM was called with the correct parameters + mock_agent.llm.generate.assert_called_once_with( + prompt=chaining_message, + tool_schema=[{"schema": "example"}], + tool_choice="required", + ) + # Assert that the tool manager was asked for the correct schema + mock_agent.tool_manager.get_all_tools_schema.assert_called_once_with( + selected_tools=["tool1"] + ) + # Assert that the output is a correctly formed Plan object + assert isinstance(result_plan, Plan) + assert result_plan.step == 5 + assert result_plan.llm_plan == "Final LLM message"