Download test/core/test_exceptions.py from MostafaRoohy/Project_CandleFetcher: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/datasets/MostafaRoohy/Project_CandleFetcher/resolve/main/test/core/test_exceptions.py
- Command line
-
hf download hf://datasets/MostafaRoohy/Project_CandleFetcher/test/core/test_exceptions.py
-
curl -L -o test_exceptions.py https://huggingface.co/datasets/MostafaRoohy/Project_CandleFetcher/resolve/main/test/core/test_exceptions.py
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 | |
| # | |
| 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')) | |
| # | |
| # | |
| ################################################################################################### | |
| ################################################################################################### | |
| ################################################################################################### | |
| # | |