Newer
Older
vmk-360-data_collector / tests / unit / test_exceptions.py
@Eugene Sukhodolskiy Eugene Sukhodolskiy 1 day ago 2 KB fix: code review critical and high issues
"""Unit tests for custom exception hierarchy."""

import pytest

from vmk_data_collector.core.exceptions import (
    AIProcessingError,
    AppError,
    DatabaseError,
    ImageDownloadError,
    NotRealEstateError,
    OllamaFatalError,
    OllamaRetryableError,
    ValidationError,
)


class TestExceptionHierarchy:
    def test_app_error_is_base(self) -> None:
        assert issubclass(AIProcessingError, AppError)
        assert issubclass(ValidationError, AppError)
        assert issubclass(DatabaseError, AppError)
        assert issubclass(ImageDownloadError, AppError)

    def test_ollama_errors_are_ai_processing(self) -> None:
        assert issubclass(OllamaRetryableError, AIProcessingError)
        assert issubclass(OllamaFatalError, AIProcessingError)

    def test_not_real_estate_is_validation(self) -> None:
        assert issubclass(NotRealEstateError, ValidationError)

    @pytest.mark.parametrize(
        "exc_class,default_msg",
        [
            (AppError, "An application error occurred"),
            (ValidationError, "Validation error"),
            (AIProcessingError, "AI processing error"),
            (OllamaRetryableError, "Ollama transient error"),
            (OllamaFatalError, "Ollama fatal error"),
            (NotRealEstateError, "Provided data is not real estate"),
            (ImageDownloadError, "Image download error"),
            (DatabaseError, "Database error"),
        ],
    )
    def test_default_message(self, exc_class, default_msg) -> None:
        exc = exc_class()
        assert exc.message == default_msg
        assert str(exc) == default_msg

    @pytest.mark.parametrize(
        "exc_class",
        [
            AppError,
            ValidationError,
            AIProcessingError,
            OllamaRetryableError,
            OllamaFatalError,
            NotRealEstateError,
            ImageDownloadError,
            DatabaseError,
        ],
    )
    def test_custom_message(self, exc_class) -> None:
        exc = exc_class("custom")
        assert exc.message == "custom"