Skip to content

Commit

Permalink
feat: add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Um Changyong committed Dec 26, 2024
1 parent b24d95f commit bd7a60b
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions tests/autorag/embedding/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import pytest
from autorag.embedding.base import EmbeddingModel


def test_load_embedding_model():
# Test loading a supported embedding model
embedding = EmbeddingModel.load("mock")
assert embedding is not None

# Test loading an unsupported embedding model
with pytest.raises(
ValueError, match="Embedding model 'unsupported_model' is not supported"
):
EmbeddingModel.load("unsupported_model")


def test_load_embedding_model_from_dict():
# Test loading with missing keys
with pytest.raises(
ValueError, match="Both 'type' and 'model_name' must be provided"
):
EmbeddingModel.load_from_dict([{"type": "openai"}])

# Test loading with unsupported type
with pytest.raises(
ValueError, match="Embedding model type 'unsupported_type' is not supported"
):
EmbeddingModel.load_from_dict(
[{"type": "unsupported_type", "model_name": "some-model"}]
)

# Test loading with multiple items
with pytest.raises(ValueError, match="Only one embedding model is supported"):
EmbeddingModel.load_from_dict(
[
{"type": "openai", "model_name": "text-embedding-ada-002"},
{"type": "huggingface", "model_name": "BAAI/bge-small-en-v1.5"},
]
)

0 comments on commit bd7a60b

Please sign in to comment.