From ee335c7862458d78996efd9cb4a8d5548e73eaaf Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 13 Mar 2025 01:13:14 +0000 Subject: [PATCH] Improve test documentation and coverage for LLM import Co-Authored-By: Joe Moura --- tests/test_import_llm.py | 56 +++++++++++++++++++++++++++++++++++----- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/tests/test_import_llm.py b/tests/test_import_llm.py index 8e23bf39e..409d3411e 100644 --- a/tests/test_import_llm.py +++ b/tests/test_import_llm.py @@ -1,23 +1,65 @@ +"""Tests for LLM import functionality.""" + import pytest + +@pytest.fixture +def bedrock_model_path(): + """Fixture providing the standard Bedrock model path for testing.""" + return "bedrock/anthropic.claude-3-sonnet-20240229-v1:0" + + def test_import_llm_from_crewai(): - """Test that LLM can be imported directly from crewai.""" + """ + Test LLM import functionality from crewai package. + + Verifies: + - Direct import of LLM class from crewai package + - Import statement succeeds without raising exceptions + """ try: from crewai import LLM assert LLM is not None except ImportError as e: pytest.fail(f"Failed to import LLM from crewai: {e}") -def test_bedrock_llm_creation(): - """Test that a Bedrock LLM can be created.""" + +def test_bedrock_llm_creation(bedrock_model_path): + """ + Test that a Bedrock LLM can be created with the correct model. + + Verifies: + - LLM can be instantiated with a Bedrock model + - The model property is correctly set to the Bedrock model path + - No exceptions are raised during instantiation + """ try: from crewai import LLM # Just test the object creation, not the actual API call - bedrock_llm = LLM( - model="bedrock/anthropic.claude-3-sonnet-20240229-v1:0" - ) + bedrock_llm = LLM(model=bedrock_model_path) assert bedrock_llm is not None - assert bedrock_llm.model == "bedrock/anthropic.claude-3-sonnet-20240229-v1:0" + assert bedrock_llm.model == bedrock_model_path except Exception as e: pytest.fail(f"Failed to create Bedrock LLM: {e}") + + + +def test_llm_with_invalid_model(): + """ + Test LLM creation with an invalid model name format. + + Verifies: + - LLM can be instantiated with any model string + - No validation errors occur during instantiation + - The model property is correctly set to the provided string + """ + try: + from crewai import LLM + + invalid_model = "invalid-model-name" + llm = LLM(model=invalid_model) + assert llm is not None + assert llm.model == invalid_model + except Exception as e: + pytest.fail(f"Failed to create LLM with invalid model: {e}")