Skip to content

Commit c91f097

Browse files
committed
refactor: update test_autoagents.py to improve validation scenarios
- Introduced an invalid configuration to simulate validation failures in tests. - Updated the first response to reflect the new invalid config structure. - Simplified mock client configuration by using a sample valid config for structured output. These changes enhance the robustness of the test cases while ensuring clarity in error handling scenarios.
1 parent f0d8b11 commit c91f097

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

src/praisonai/tests/unit/test_autoagents.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,31 @@ 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: malformed JSON that will fail parsing
551-
first_response = "{ invalid json structure"
550+
# Create an invalid config that will fail validation (not JSON parsing)
551+
invalid_config = AutoAgentsConfig(
552+
main_instruction="Test",
553+
process_type="sequential",
554+
agents=[
555+
AgentConfig(
556+
name="Agent",
557+
role="Role",
558+
goal="Goal",
559+
backstory="Story",
560+
tools=[],
561+
tasks=[
562+
TaskConfig(
563+
name="", # Invalid: empty name
564+
description="Description",
565+
expected_output="Output",
566+
tools=[]
567+
)
568+
]
569+
)
570+
]
571+
)
572+
573+
# First response: invalid config that will fail validation
574+
first_response = json.dumps(invalid_config.model_dump())
552575

553576
# Second response: valid config
554577
second_response = json.dumps(sample_valid_config.model_dump())
@@ -587,32 +610,9 @@ def test_custom_api_key_and_base_url(self, mock_get_client, mock_openai_class, m
587610
# Mock support for structured outputs
588611
mock_supports_structured.return_value = True
589612

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-
613613
# Mock OpenAI client instance
614614
mock_client = Mock(spec=OpenAIClient)
615-
mock_client.parse_structured_output.return_value = serializable_config
615+
mock_client.parse_structured_output.return_value = sample_valid_config
616616
mock_openai_class.return_value = mock_client
617617

618618
custom_api_key = "custom-api-key"

0 commit comments

Comments
 (0)