File size: 3,142 Bytes
4d127e7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | """
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'))
#
#
###################################################################################################
###################################################################################################
###################################################################################################
#
|