chunker and ui
This commit is contained in:
69
tests/chunker/test_exceptions.py
Normal file
69
tests/chunker/test_exceptions.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Tests for exception hierarchy — catch patterns, attributes.
|
||||
|
||||
Demonstrates: TDD (Interview Topic 8) — testing exception design.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
|
||||
from core.chunker.exceptions import (
|
||||
ChunkChecksumError,
|
||||
ChunkError,
|
||||
ChunkReadError,
|
||||
PipelineError,
|
||||
ProcessingError,
|
||||
ProcessorFailureError,
|
||||
ProcessorTimeoutError,
|
||||
ReassemblyError,
|
||||
)
|
||||
|
||||
|
||||
class TestExceptionHierarchy:
|
||||
"""Verify the exception class hierarchy and catch patterns."""
|
||||
|
||||
def test_pipeline_error_is_base(self):
|
||||
"""All chunker exceptions inherit from PipelineError."""
|
||||
assert issubclass(ChunkError, PipelineError)
|
||||
assert issubclass(ProcessingError, PipelineError)
|
||||
assert issubclass(ReassemblyError, PipelineError)
|
||||
|
||||
def test_chunk_error_subtypes(self):
|
||||
"""ChunkReadError and ChunkChecksumError are ChunkErrors."""
|
||||
assert issubclass(ChunkReadError, ChunkError)
|
||||
assert issubclass(ChunkChecksumError, ChunkError)
|
||||
|
||||
def test_processing_error_subtypes(self):
|
||||
"""ProcessorTimeoutError and ProcessorFailureError are ProcessingErrors."""
|
||||
assert issubclass(ProcessorTimeoutError, ProcessingError)
|
||||
assert issubclass(ProcessorFailureError, ProcessingError)
|
||||
|
||||
def test_catch_pipeline_error_catches_all(self):
|
||||
"""Catching PipelineError catches any subtype."""
|
||||
with pytest.raises(PipelineError):
|
||||
raise ChunkReadError("test")
|
||||
|
||||
with pytest.raises(PipelineError):
|
||||
raise ReassemblyError("test")
|
||||
|
||||
def test_checksum_error_attributes(self):
|
||||
"""ChunkChecksumError carries sequence, expected, actual."""
|
||||
err = ChunkChecksumError(sequence=5, expected="aaa", actual="bbb")
|
||||
assert err.sequence == 5
|
||||
assert err.expected == "aaa"
|
||||
assert err.actual == "bbb"
|
||||
assert "5" in str(err)
|
||||
|
||||
def test_timeout_error_attributes(self):
|
||||
"""ProcessorTimeoutError carries sequence and timeout."""
|
||||
err = ProcessorTimeoutError(sequence=3, timeout=30.0)
|
||||
assert err.sequence == 3
|
||||
assert err.timeout == 30.0
|
||||
|
||||
def test_failure_error_attributes(self):
|
||||
"""ProcessorFailureError carries sequence, retries, original error."""
|
||||
original = RuntimeError("boom")
|
||||
err = ProcessorFailureError(sequence=1, retries=3, original_error=original)
|
||||
assert err.sequence == 1
|
||||
assert err.retries == 3
|
||||
assert err.original_error is original
|
||||
assert "boom" in str(err)
|
||||
Reference in New Issue
Block a user