feat(v0.1.0): project foundation with logging and config
This commit is contained in:
90
tests/unit/test_core/test_exceptions.py
Normal file
90
tests/unit/test_core/test_exceptions.py
Normal file
@@ -0,0 +1,90 @@
|
||||
"""Tests for custom exception classes."""
|
||||
|
||||
import pytest
|
||||
|
||||
from src.core.exceptions import (
|
||||
ConfigurationError,
|
||||
DataError,
|
||||
DetectorError,
|
||||
ICTTradingException,
|
||||
ModelError,
|
||||
TradingError,
|
||||
ValidationError,
|
||||
)
|
||||
|
||||
|
||||
def test_base_exception():
|
||||
"""Test base exception class."""
|
||||
exc = ICTTradingException("Test message")
|
||||
assert str(exc) == "Test message"
|
||||
assert exc.message == "Test message"
|
||||
assert exc.error_code is None
|
||||
assert exc.context == {}
|
||||
|
||||
|
||||
def test_exception_with_error_code():
|
||||
"""Test exception with error code."""
|
||||
exc = ICTTradingException("Test message", error_code="TEST_ERROR")
|
||||
assert str(exc) == "[TEST_ERROR] Test message"
|
||||
assert exc.error_code == "TEST_ERROR"
|
||||
|
||||
|
||||
def test_exception_with_context():
|
||||
"""Test exception with context."""
|
||||
context = {"key": "value", "number": 42}
|
||||
exc = ICTTradingException("Test message", context=context)
|
||||
assert exc.context == context
|
||||
assert exc.to_dict()["context"] == context
|
||||
|
||||
|
||||
def test_exception_to_dict():
|
||||
"""Test exception to_dict method."""
|
||||
exc = ICTTradingException("Test message", error_code="TEST", context={"key": "value"})
|
||||
exc_dict = exc.to_dict()
|
||||
assert exc_dict["error_type"] == "ICTTradingException"
|
||||
assert exc_dict["error_code"] == "TEST"
|
||||
assert exc_dict["message"] == "Test message"
|
||||
assert exc_dict["context"] == {"key": "value"}
|
||||
|
||||
|
||||
def test_data_error():
|
||||
"""Test DataError exception."""
|
||||
exc = DataError("Data loading failed")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "DATA_ERROR"
|
||||
|
||||
|
||||
def test_detector_error():
|
||||
"""Test DetectorError exception."""
|
||||
exc = DetectorError("Detection failed")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "DETECTOR_ERROR"
|
||||
|
||||
|
||||
def test_model_error():
|
||||
"""Test ModelError exception."""
|
||||
exc = ModelError("Model training failed")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "MODEL_ERROR"
|
||||
|
||||
|
||||
def test_configuration_error():
|
||||
"""Test ConfigurationError exception."""
|
||||
exc = ConfigurationError("Invalid config")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "CONFIG_ERROR"
|
||||
|
||||
|
||||
def test_trading_error():
|
||||
"""Test TradingError exception."""
|
||||
exc = TradingError("Trade execution failed")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "TRADING_ERROR"
|
||||
|
||||
|
||||
def test_validation_error():
|
||||
"""Test ValidationError exception."""
|
||||
exc = ValidationError("Validation failed")
|
||||
assert isinstance(exc, ICTTradingException)
|
||||
assert exc.error_code == "VALIDATION_ERROR"
|
||||
|
||||
Reference in New Issue
Block a user