OPEN SOURCE
software/tests/test_exceptions.py
このサイトで読み、必要なファイルを保存できます。
日常訳はAIを用いて作成された翻訳です。人間の聖書学・原語の専門家による全訳の検証は確認されていません。既存の翻訳や原語資料と照らし合わせてお読みください。
1"""Tests for custom exception hierarchy."""23import pytest45from src.exceptions import (6ChunkParsingError,7CLINotFoundError,8ClaudeAPIError,9ConfigurationError,10EvaluationError,11GlossaryMatchError,12InvalidReferenceError,13ModelNotFoundError,14PericopeNotFoundError,15QualityThresholdError,16RateLimitError,17StorageError,18TranslationError,19VerseNotFoundError,20classify_claude_error,21)222324class TestTranslationError:25"""Tests for base TranslationError."""2627def test_basic_creation(self):28"""Test basic error creation."""29error = TranslationError("Test error")30assert str(error) == "Test error"31assert error.details == {}3233def test_with_details(self):34"""Test error with details."""35error = TranslationError("Test error", {"key": "value"})36assert error.details == {"key": "value"}373839class TestClaudeAPIError:40"""Tests for ClaudeAPIError."""4142def test_basic_creation(self):43"""Test basic error creation."""44error = ClaudeAPIError("API error")45assert str(error) == "API error"46assert error.stderr is None47assert error.return_code is None4849def test_with_stderr_and_code(self):50"""Test error with stderr and return code."""51error = ClaudeAPIError("API error", stderr="Error output", return_code=1)52assert error.stderr == "Error output"53assert error.return_code == 154assert error.details["stderr"] == "Error output"55assert error.details["return_code"] == 1565758class TestRateLimitError:59"""Tests for RateLimitError."""6061def test_default_message(self):62"""Test default error message."""63error = RateLimitError()64assert "Rate limit" in str(error)65assert error.retry_after is None6667def test_with_retry_after(self):68"""Test error with retry_after."""69error = RateLimitError("Rate limit hit", retry_after=30.0)70assert error.retry_after == 30.071assert error.details["retry_after"] == 30.0727374class TestModelNotFoundError:75"""Tests for ModelNotFoundError."""7677def test_creation(self):78"""Test error creation."""79error = ModelNotFoundError("claude-invalid-model")80assert "claude-invalid-model" in str(error)81assert error.model == "claude-invalid-model"82assert error.details["model"] == "claude-invalid-model"838485class TestCLINotFoundError:86"""Tests for CLINotFoundError."""8788def test_creation(self):89"""Test error creation."""90error = CLINotFoundError()91assert "Claude CLI not found" in str(error)92assert "npm install" in str(error)939495class TestVerseNotFoundError:96"""Tests for VerseNotFoundError."""9798def test_creation(self):99"""Test error creation."""100error = VerseNotFoundError("john", 1, 1)101assert "john 1:1" in str(error)102assert error.book == "john"103assert error.chapter == 1104assert error.verse == 1105assert error.details == {"book": "john", "chapter": 1, "verse": 1}106107108class TestInvalidReferenceError:109"""Tests for InvalidReferenceError."""110111def test_basic_creation(self):112"""Test basic error creation."""113error = InvalidReferenceError("bad:ref")114assert "bad:ref" in str(error)115assert error.reference == "bad:ref"116assert error.reason is None117118def test_with_reason(self):119"""Test error with reason."""120error = InvalidReferenceError("bad:ref", "Invalid format")121assert "Invalid format" in str(error)122assert error.reason == "Invalid format"123124125class TestChunkParsingError:126"""Tests for ChunkParsingError."""127128def test_basic_creation(self):129"""Test basic error creation."""130error = ChunkParsingError("Parse failed")131assert str(error) == "Parse failed"132assert error.response is None133assert error.expected_verses is None134135def test_with_context(self):136"""Test error with response context."""137error = ChunkParsingError(138"Parse failed",139response="Not JSON",140expected_verses=["1:1", "1:2"],141)142assert error.response == "Not JSON"143assert error.expected_verses == ["1:1", "1:2"]144assert error.details["expected_verses"] == ["1:1", "1:2"]145146147class TestPericopeNotFoundError:148"""Tests for PericopeNotFoundError."""149150def test_creation(self):151"""Test error creation."""152error = PericopeNotFoundError("john-prologue")153assert "john-prologue" in str(error)154assert error.pericope_id == "john-prologue"155156157class TestEvaluationError:158"""Tests for EvaluationError."""159160def test_basic_creation(self):161"""Test basic error creation."""162error = EvaluationError("Eval failed")163assert str(error) == "Eval failed"164assert error.verse_ref is None165assert error.dimension is None166167def test_with_context(self):168"""Test error with verse and dimension context."""169error = EvaluationError(170"Eval failed",171verse_ref="john 1:1",172dimension="theological_accuracy",173)174assert error.verse_ref == "john 1:1"175assert error.dimension == "theological_accuracy"176177178class TestQualityThresholdError:179"""Tests for QualityThresholdError."""180181def test_creation(self):182"""Test error creation."""183error = QualityThresholdError(184"Quality too low",185score=65.0,186threshold=70.0,187)188assert "Quality too low" in str(error)189assert error.score == 65.0190assert error.threshold == 70.0191assert error.dimension is None192193def test_with_dimension(self):194"""Test error with specific dimension."""195error = QualityThresholdError(196"Theology score low",197score=60.0,198threshold=75.0,199dimension="theological_accuracy",200)201assert error.dimension == "theological_accuracy"202203204class TestStorageError:205"""Tests for StorageError."""206207def test_basic_creation(self):208"""Test basic error creation."""209error = StorageError("Storage failed")210assert str(error) == "Storage failed"211assert error.path is None212assert error.operation is None213214def test_with_context(self):215"""Test error with path and operation context."""216error = StorageError(217"Write failed",218path="/data/file.json",219operation="write",220)221assert error.path == "/data/file.json"222assert error.operation == "write"223224225class TestGlossaryMatchError:226"""Tests for GlossaryMatchError."""227228def test_basic_creation(self):229"""Test basic error creation."""230error = GlossaryMatchError("Match failed")231assert str(error) == "Match failed"232assert error.term is None233234def test_with_term(self):235"""Test error with term context."""236error = GlossaryMatchError("Match failed", term="λόγος")237assert error.term == "λόγος"238239240class TestConfigurationError:241"""Tests for ConfigurationError."""242243def test_basic_creation(self):244"""Test basic error creation."""245error = ConfigurationError("Config invalid")246assert str(error) == "Config invalid"247assert error.config_key is None248249def test_with_key(self):250"""Test error with config key context."""251error = ConfigurationError("Invalid value", config_key="model")252assert error.config_key == "model"253254255class TestClassifyClaudeError:256"""Tests for classify_claude_error function."""257258def test_rate_limit_detection(self):259"""Test rate limit error detection."""260error = classify_claude_error("Error: rate limit exceeded", 1)261assert isinstance(error, RateLimitError)262263def test_rate_limit_detection_429(self):264"""Test rate limit error detection via 429."""265error = classify_claude_error("HTTP 429 Too Many Requests", 1)266assert isinstance(error, RateLimitError)267268def test_model_error_detection(self):269"""Test model error detection."""270error = classify_claude_error("Model not found: invalid-model", 1)271assert isinstance(error, ClaudeAPIError)272assert "Model error" in str(error)273274def test_cli_not_found_detection(self):275"""Test CLI not found detection."""276error = classify_claude_error("command not found", 127)277assert isinstance(error, CLINotFoundError)278279def test_network_error_detection(self):280"""Test network error detection."""281error = classify_claude_error("Network connection failed", 1)282assert isinstance(error, ClaudeAPIError)283assert "Network error" in str(error)284285def test_timeout_detection(self):286"""Test timeout error detection."""287error = classify_claude_error("Request timeout", 1)288assert isinstance(error, ClaudeAPIError)289assert "Network error" in str(error)290291def test_generic_error(self):292"""Test generic error fallback."""293error = classify_claude_error("Unknown error occurred", 1)294assert isinstance(error, ClaudeAPIError)295assert "Claude CLI failed" in str(error)296