|
| 1 | +"""Tests for Watson embedding function name method.""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from unittest.mock import patch, MagicMock |
| 5 | + |
| 6 | +from crewai.rag.embeddings.providers.ibm.embedding_callable import WatsonEmbeddingFunction |
| 7 | + |
| 8 | + |
| 9 | +class TestWatsonEmbeddingName: |
| 10 | + """Test Watson embedding function name method.""" |
| 11 | + |
| 12 | + def test_watson_embedding_function_has_name_method(self): |
| 13 | + """Test that WatsonEmbeddingFunction has a name method.""" |
| 14 | + assert hasattr(WatsonEmbeddingFunction, 'name') |
| 15 | + assert callable(getattr(WatsonEmbeddingFunction, 'name')) |
| 16 | + |
| 17 | + def test_watson_embedding_function_name_returns_watson(self): |
| 18 | + """Test that the name method returns 'watson'.""" |
| 19 | + assert WatsonEmbeddingFunction.name() == "watson" |
| 20 | + |
| 21 | + def test_watson_embedding_function_name_is_static(self): |
| 22 | + """Test that the name method can be called without instantiation.""" |
| 23 | + name = WatsonEmbeddingFunction.name() |
| 24 | + assert name == "watson" |
| 25 | + assert isinstance(name, str) |
| 26 | + |
| 27 | + def test_watson_embedding_function_name_with_chromadb_validation(self): |
| 28 | + """Test that the name method works in ChromaDB validation scenario.""" |
| 29 | + config = { |
| 30 | + "model_id": "test-model", |
| 31 | + "api_key": "test-key", |
| 32 | + "url": "https://test.com" |
| 33 | + } |
| 34 | + |
| 35 | + watson_func = WatsonEmbeddingFunction(**config) |
| 36 | + |
| 37 | + try: |
| 38 | + name = watson_func.name() |
| 39 | + assert name == "watson" |
| 40 | + except AttributeError as e: |
| 41 | + pytest.fail(f"ChromaDB validation failed with AttributeError: {e}") |
| 42 | + |
| 43 | + def test_watson_embedding_function_name_method_signature(self): |
| 44 | + """Test that the name method has the correct signature.""" |
| 45 | + import inspect |
| 46 | + |
| 47 | + name_method = getattr(WatsonEmbeddingFunction, 'name') |
| 48 | + |
| 49 | + assert isinstance(inspect.getattr_static(WatsonEmbeddingFunction, 'name'), staticmethod) |
| 50 | + |
| 51 | + sig = inspect.signature(name_method) |
| 52 | + if sig.return_annotation != inspect.Signature.empty: |
| 53 | + assert sig.return_annotation == str |
| 54 | + |
| 55 | + def test_watson_embedding_function_reproduces_original_issue(self): |
| 56 | + """Test that reproduces the original issue scenario from #3597.""" |
| 57 | + |
| 58 | + |
| 59 | + config = { |
| 60 | + "model_id": "ibm/slate-125m-english-rtrvr", |
| 61 | + "api_key": "test-key", |
| 62 | + "url": "https://us-south.ml.cloud.ibm.com", |
| 63 | + "project_id": "test-project" |
| 64 | + } |
| 65 | + |
| 66 | + watson_func = WatsonEmbeddingFunction(**config) |
| 67 | + |
| 68 | + name = watson_func.name() |
| 69 | + |
| 70 | + assert name == "watson" |
| 71 | + assert isinstance(name, str) |
| 72 | + |
| 73 | + class_name = WatsonEmbeddingFunction.name() |
| 74 | + assert class_name == "watson" |
| 75 | + assert class_name == name |
0 commit comments