Project_CandleFetcher / test /core /test_exceptions.py
MostafaRoohy's picture
Snapshot: candle dataset tip (12 Oct 2026)
b627480
Raw History Blame Contribute Delete
3.14 kB
"""
Tests for the canonical exception hierarchy.
The hierarchy is a public contract: every fetcher and every downstream consumer
catches these types, so subclass relationships must stay stable and every public
error must remain a `CandleFetcherError`.
"""
from __future__ import annotations
#
###################################################################################################
###################################################################################################
################################################################################################### Standard Modules
#
import pytest
#
###################################################################################################
###################################################################################################
################################################################################################### My Modules
#
from candlefetcher.core.exceptions import (
CandleFetcherError,
CapabilityError,
ConfigurationError,
DataError,
ValidationError,
)
#
###################################################################################################
###################################################################################################
################################################################################################### Exception Hierarchy
#
@pytest.mark.parametrize(
'error_type',
[
ConfigurationError,
ValidationError,
DataError,
CapabilityError,
],
)
def test_every_public_error_is_a_candle_fetcher_error(error_type:type[Exception]) -> None:
"""Every public error remains catchable through the single package error base."""
error = error_type('boom')
assert (isinstance(error, CandleFetcherError))
assert (isinstance(error, Exception))
assert (str(error) == 'boom')
#
def test_validation_and_data_errors_are_direct_children() -> None:
"""Validation and data errors are siblings, neither swallowing the other."""
assert (issubclass(ValidationError, CandleFetcherError))
assert (issubclass(DataError, CandleFetcherError))
assert (not issubclass(DataError, ValidationError))
assert (not issubclass(ValidationError, DataError))
#
def test_capability_error_is_a_configuration_error() -> None:
"""Capability mismatches are configuration incompatibilities by design."""
assert (issubclass(CapabilityError, ConfigurationError))
assert (issubclass(CapabilityError, CandleFetcherError))
#
def test_errors_can_be_raised_and_caught_through_the_base() -> None:
"""A generic `except CandleFetcherError` catches the whole family."""
with pytest.raises(CandleFetcherError):
raise (ValidationError('caught through the base'))
#
#
###################################################################################################
###################################################################################################
###################################################################################################
#