Pre-publication review draft
日常訳NICHIJOYAKU日本語 ↗

OPEN SOURCE

software/tests/test_exceptions.py

Read on this site and download the files you need.

Nichijoyaku was created using AI. A complete review by human biblical-language and biblical-studies specialists has not been established. Read alongside established translations and original-language resources.

← Back to the open-source guide

software/tests/test_exceptions.py296 linesDownload this file ↓

This is the same source included in the download. Each line number is a link you can save or share.

File verification detailsSHA-256 960118cd86d728489cba4ebeb3b5355e28a9ecb9784a145b3047a5664f2663b9
1"""Tests for custom exception hierarchy."""23import pytest45from src.exceptions import (6    ChunkParsingError,7    CLINotFoundError,8    ClaudeAPIError,9    ConfigurationError,10    EvaluationError,11    GlossaryMatchError,12    InvalidReferenceError,13    ModelNotFoundError,14    PericopeNotFoundError,15    QualityThresholdError,16    RateLimitError,17    StorageError,18    TranslationError,19    VerseNotFoundError,20    classify_claude_error,21)222324class TestTranslationError:25    """Tests for base TranslationError."""2627    def test_basic_creation(self):28        """Test basic error creation."""29        error = TranslationError("Test error")30        assert str(error) == "Test error"31        assert error.details == {}3233    def test_with_details(self):34        """Test error with details."""35        error = TranslationError("Test error", {"key": "value"})36        assert error.details == {"key": "value"}373839class TestClaudeAPIError:40    """Tests for ClaudeAPIError."""4142    def test_basic_creation(self):43        """Test basic error creation."""44        error = ClaudeAPIError("API error")45        assert str(error) == "API error"46        assert error.stderr is None47        assert error.return_code is None4849    def test_with_stderr_and_code(self):50        """Test error with stderr and return code."""51        error = ClaudeAPIError("API error", stderr="Error output", return_code=1)52        assert error.stderr == "Error output"53        assert error.return_code == 154        assert error.details["stderr"] == "Error output"55        assert error.details["return_code"] == 1565758class TestRateLimitError:59    """Tests for RateLimitError."""6061    def test_default_message(self):62        """Test default error message."""63        error = RateLimitError()64        assert "Rate limit" in str(error)65        assert error.retry_after is None6667    def test_with_retry_after(self):68        """Test error with retry_after."""69        error = RateLimitError("Rate limit hit", retry_after=30.0)70        assert error.retry_after == 30.071        assert error.details["retry_after"] == 30.0727374class TestModelNotFoundError:75    """Tests for ModelNotFoundError."""7677    def test_creation(self):78        """Test error creation."""79        error = ModelNotFoundError("claude-invalid-model")80        assert "claude-invalid-model" in str(error)81        assert error.model == "claude-invalid-model"82        assert error.details["model"] == "claude-invalid-model"838485class TestCLINotFoundError:86    """Tests for CLINotFoundError."""8788    def test_creation(self):89        """Test error creation."""90        error = CLINotFoundError()91        assert "Claude CLI not found" in str(error)92        assert "npm install" in str(error)939495class TestVerseNotFoundError:96    """Tests for VerseNotFoundError."""9798    def test_creation(self):99        """Test error creation."""100        error = VerseNotFoundError("john", 1, 1)101        assert "john 1:1" in str(error)102        assert error.book == "john"103        assert error.chapter == 1104        assert error.verse == 1105        assert error.details == {"book": "john", "chapter": 1, "verse": 1}106107108class TestInvalidReferenceError:109    """Tests for InvalidReferenceError."""110111    def test_basic_creation(self):112        """Test basic error creation."""113        error = InvalidReferenceError("bad:ref")114        assert "bad:ref" in str(error)115        assert error.reference == "bad:ref"116        assert error.reason is None117118    def test_with_reason(self):119        """Test error with reason."""120        error = InvalidReferenceError("bad:ref", "Invalid format")121        assert "Invalid format" in str(error)122        assert error.reason == "Invalid format"123124125class TestChunkParsingError:126    """Tests for ChunkParsingError."""127128    def test_basic_creation(self):129        """Test basic error creation."""130        error = ChunkParsingError("Parse failed")131        assert str(error) == "Parse failed"132        assert error.response is None133        assert error.expected_verses is None134135    def test_with_context(self):136        """Test error with response context."""137        error = ChunkParsingError(138            "Parse failed",139            response="Not JSON",140            expected_verses=["1:1", "1:2"],141        )142        assert error.response == "Not JSON"143        assert error.expected_verses == ["1:1", "1:2"]144        assert error.details["expected_verses"] == ["1:1", "1:2"]145146147class TestPericopeNotFoundError:148    """Tests for PericopeNotFoundError."""149150    def test_creation(self):151        """Test error creation."""152        error = PericopeNotFoundError("john-prologue")153        assert "john-prologue" in str(error)154        assert error.pericope_id == "john-prologue"155156157class TestEvaluationError:158    """Tests for EvaluationError."""159160    def test_basic_creation(self):161        """Test basic error creation."""162        error = EvaluationError("Eval failed")163        assert str(error) == "Eval failed"164        assert error.verse_ref is None165        assert error.dimension is None166167    def test_with_context(self):168        """Test error with verse and dimension context."""169        error = EvaluationError(170            "Eval failed",171            verse_ref="john 1:1",172            dimension="theological_accuracy",173        )174        assert error.verse_ref == "john 1:1"175        assert error.dimension == "theological_accuracy"176177178class TestQualityThresholdError:179    """Tests for QualityThresholdError."""180181    def test_creation(self):182        """Test error creation."""183        error = QualityThresholdError(184            "Quality too low",185            score=65.0,186            threshold=70.0,187        )188        assert "Quality too low" in str(error)189        assert error.score == 65.0190        assert error.threshold == 70.0191        assert error.dimension is None192193    def test_with_dimension(self):194        """Test error with specific dimension."""195        error = QualityThresholdError(196            "Theology score low",197            score=60.0,198            threshold=75.0,199            dimension="theological_accuracy",200        )201        assert error.dimension == "theological_accuracy"202203204class TestStorageError:205    """Tests for StorageError."""206207    def test_basic_creation(self):208        """Test basic error creation."""209        error = StorageError("Storage failed")210        assert str(error) == "Storage failed"211        assert error.path is None212        assert error.operation is None213214    def test_with_context(self):215        """Test error with path and operation context."""216        error = StorageError(217            "Write failed",218            path="/data/file.json",219            operation="write",220        )221        assert error.path == "/data/file.json"222        assert error.operation == "write"223224225class TestGlossaryMatchError:226    """Tests for GlossaryMatchError."""227228    def test_basic_creation(self):229        """Test basic error creation."""230        error = GlossaryMatchError("Match failed")231        assert str(error) == "Match failed"232        assert error.term is None233234    def test_with_term(self):235        """Test error with term context."""236        error = GlossaryMatchError("Match failed", term="λόγος")237        assert error.term == "λόγος"238239240class TestConfigurationError:241    """Tests for ConfigurationError."""242243    def test_basic_creation(self):244        """Test basic error creation."""245        error = ConfigurationError("Config invalid")246        assert str(error) == "Config invalid"247        assert error.config_key is None248249    def test_with_key(self):250        """Test error with config key context."""251        error = ConfigurationError("Invalid value", config_key="model")252        assert error.config_key == "model"253254255class TestClassifyClaudeError:256    """Tests for classify_claude_error function."""257258    def test_rate_limit_detection(self):259        """Test rate limit error detection."""260        error = classify_claude_error("Error: rate limit exceeded", 1)261        assert isinstance(error, RateLimitError)262263    def test_rate_limit_detection_429(self):264        """Test rate limit error detection via 429."""265        error = classify_claude_error("HTTP 429 Too Many Requests", 1)266        assert isinstance(error, RateLimitError)267268    def test_model_error_detection(self):269        """Test model error detection."""270        error = classify_claude_error("Model not found: invalid-model", 1)271        assert isinstance(error, ClaudeAPIError)272        assert "Model error" in str(error)273274    def test_cli_not_found_detection(self):275        """Test CLI not found detection."""276        error = classify_claude_error("command not found", 127)277        assert isinstance(error, CLINotFoundError)278279    def test_network_error_detection(self):280        """Test network error detection."""281        error = classify_claude_error("Network connection failed", 1)282        assert isinstance(error, ClaudeAPIError)283        assert "Network error" in str(error)284285    def test_timeout_detection(self):286        """Test timeout error detection."""287        error = classify_claude_error("Request timeout", 1)288        assert isinstance(error, ClaudeAPIError)289        assert "Network error" in str(error)290291    def test_generic_error(self):292        """Test generic error fallback."""293        error = classify_claude_error("Unknown error occurred", 1)294        assert isinstance(error, ClaudeAPIError)295        assert "Claude CLI failed" in str(error)296