Skip to content

Commit f0d8b11

Browse files
committed
refactor: enhance test_autoagents.py with improved mock configuration
- Updated the first response to use a malformed JSON string for clarity in error simulation. - Introduced a serializable configuration for the mock client to ensure valid data handling in tests. - Enhanced comments for better understanding of the test setup and scenarios. These changes improve the clarity and robustness of the test cases while maintaining the integrity of the testing framework.
1 parent 8550090 commit f0d8b11

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

src/praisonai/tests/unit/test_autoagents.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -547,19 +547,8 @@ def test_retry_with_previous_response_in_prompt(self, mock_llm_class, mock_suppo
547547
# Mock LLM instance
548548
mock_llm = Mock()
549549

550-
# First response: invalid JSON that will fail validation
551-
first_response = json.dumps({
552-
"main_instruction": "Test",
553-
"process_type": "sequential",
554-
"agents": [{
555-
"name": "Agent",
556-
"role": "Role",
557-
"goal": "Goal",
558-
"backstory": "Story",
559-
"tools": [],
560-
"tasks": ["String task instead of object"]
561-
}]
562-
})
550+
# First response: malformed JSON that will fail parsing
551+
first_response = "{ invalid json structure"
563552

564553
# Second response: valid config
565554
second_response = json.dumps(sample_valid_config.model_dump())
@@ -598,9 +587,32 @@ def test_custom_api_key_and_base_url(self, mock_get_client, mock_openai_class, m
598587
# Mock support for structured outputs
599588
mock_supports_structured.return_value = True
600589

590+
# Create a proper mock config with serializable data
591+
serializable_config = AutoAgentsConfig(
592+
main_instruction="Test",
593+
process_type="sequential",
594+
agents=[
595+
AgentConfig(
596+
name="Test Agent",
597+
role="Tester",
598+
goal="Test goal",
599+
backstory="Test story",
600+
tools=[],
601+
tasks=[
602+
TaskConfig(
603+
name="Test Task",
604+
description="Test description",
605+
expected_output="Test output",
606+
tools=[]
607+
)
608+
]
609+
)
610+
]
611+
)
612+
601613
# Mock OpenAI client instance
602614
mock_client = Mock(spec=OpenAIClient)
603-
mock_client.parse_structured_output.return_value = sample_valid_config
615+
mock_client.parse_structured_output.return_value = serializable_config
604616
mock_openai_class.return_value = mock_client
605617

606618
custom_api_key = "custom-api-key"

0 commit comments

Comments
 (0)