forked from innovacion/searchbox
Add custom exceptions
This commit is contained in:
@@ -2,7 +2,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from vector_search_mcp.engine import Backend, get_engine
|
||||
from vector_search_mcp.engine import Backend, get_engine, UnknownEngineError
|
||||
from vector_search_mcp.engine.base_engine import BaseEngine
|
||||
from vector_search_mcp.engine.qdrant_engine import QdrantEngine
|
||||
|
||||
@@ -52,7 +52,7 @@ class TestEngineFactory:
|
||||
# Create an invalid engine type (bypassing enum validation)
|
||||
invalid_type = "invalid_engine"
|
||||
|
||||
with pytest.raises(ValueError, match="Unknown engine type: invalid_engine"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type: invalid_engine"):
|
||||
# We need to cast to bypass type checking
|
||||
get_engine(invalid_type) # type: ignore
|
||||
|
||||
@@ -234,22 +234,22 @@ class TestEngineFactoryErrorHandling:
|
||||
|
||||
def test_none_backend_type(self):
|
||||
"""Test get_engine with None raises appropriate error"""
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
with pytest.raises((TypeError, UnknownEngineError)):
|
||||
get_engine(None) # type: ignore
|
||||
|
||||
def test_empty_string_backend_type(self):
|
||||
"""Test get_engine with empty string"""
|
||||
with pytest.raises(ValueError, match="Unknown engine type"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type"):
|
||||
get_engine("") # type: ignore
|
||||
|
||||
def test_numeric_backend_type(self):
|
||||
"""Test get_engine with numeric input"""
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
with pytest.raises((TypeError, UnknownEngineError)):
|
||||
get_engine(123) # type: ignore
|
||||
|
||||
def test_boolean_backend_type(self):
|
||||
"""Test get_engine with boolean input"""
|
||||
with pytest.raises((TypeError, ValueError)):
|
||||
with pytest.raises((TypeError, UnknownEngineError)):
|
||||
get_engine(True) # type: ignore
|
||||
|
||||
def test_get_engine_cosmos_not_implemented(self):
|
||||
@@ -273,16 +273,16 @@ class TestEngineFactoryErrorHandling:
|
||||
|
||||
def test_case_sensitive_backend_type(self):
|
||||
"""Test that backend type matching is case sensitive"""
|
||||
with pytest.raises(ValueError, match="Unknown engine type"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type"):
|
||||
get_engine("QDRANT") # type: ignore
|
||||
|
||||
with pytest.raises(ValueError, match="Unknown engine type"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type"):
|
||||
get_engine("Qdrant") # type: ignore
|
||||
|
||||
def test_whitespace_backend_type(self):
|
||||
"""Test backend type with whitespace"""
|
||||
with pytest.raises(ValueError, match="Unknown engine type"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type"):
|
||||
get_engine(" qdrant ") # type: ignore
|
||||
|
||||
with pytest.raises(ValueError, match="Unknown engine type"):
|
||||
with pytest.raises(UnknownEngineError, match="Unknown engine type"):
|
||||
get_engine("\tqdrant\n") # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user