kerdosai / tests /test_exceptions.py
Anonymous Hunter
feat: Add robust configuration management, Docker support, initial testing, and quickstart documentation.
f21249a
"""
Unit tests for custom exceptions.
"""
import pytest
from exceptions import (
KerdosError,
ConfigurationError,
ModelError,
ModelLoadError,
DataError,
DataValidationError,
TrainingError,
DeploymentError
)
class TestKerdosError:
"""Tests for base KerdosError."""
def test_basic_error(self):
"""Test basic error creation."""
error = KerdosError("Test error")
assert str(error) == "Test error"
assert error.message == "Test error"
assert error.details == {}
def test_error_with_details(self):
"""Test error with details."""
error = KerdosError(
"Test error",
details={"key": "value", "number": 42}
)
assert "Test error" in str(error)
assert "key=value" in str(error)
assert "number=42" in str(error)
def test_error_inheritance(self):
"""Test that KerdosError inherits from Exception."""
error = KerdosError("Test")
assert isinstance(error, Exception)
class TestSpecificErrors:
"""Tests for specific error types."""
def test_configuration_error(self):
"""Test ConfigurationError."""
error = ConfigurationError("Invalid config")
assert isinstance(error, KerdosError)
assert str(error) == "Invalid config"
def test_model_error(self):
"""Test ModelError."""
error = ModelError("Model failed")
assert isinstance(error, KerdosError)
def test_model_load_error(self):
"""Test ModelLoadError."""
error = ModelLoadError(
"Failed to load model",
details={"path": "/path/to/model"}
)
assert isinstance(error, ModelError)
assert "path=/path/to/model" in str(error)
def test_data_validation_error(self):
"""Test DataValidationError."""
error = DataValidationError(
"Invalid data format",
details={"expected": "json", "got": "csv"}
)
assert isinstance(error, DataError)
assert "expected=json" in str(error)
def test_training_error(self):
"""Test TrainingError."""
error = TrainingError("Training failed")
assert isinstance(error, KerdosError)
def test_deployment_error(self):
"""Test DeploymentError."""
error = DeploymentError("Deployment failed")
assert isinstance(error, KerdosError)
class TestErrorRaising:
"""Tests for raising and catching errors."""
def test_raise_and_catch(self):
"""Test raising and catching KerdosError."""
with pytest.raises(KerdosError) as exc_info:
raise KerdosError("Test error")
assert str(exc_info.value) == "Test error"
def test_catch_specific_error(self):
"""Test catching specific error types."""
with pytest.raises(ConfigurationError):
raise ConfigurationError("Config error")
def test_catch_base_error(self):
"""Test catching base error catches specific errors."""
with pytest.raises(KerdosError):
raise ConfigurationError("Config error")