Files
wehub-resource-sync e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:00:43 +08:00

43 lines
1.5 KiB
Python

"""Tests for LLM error mapping helpers."""
from deeptutor.services.llm.error_mapping import map_error
from deeptutor.services.llm.exceptions import (
LLMAPIError,
LLMAuthenticationError,
LLMRateLimitError,
ProviderContextWindowError,
)
class DummyError(Exception):
"""Custom error used for mapping tests."""
def __init__(self, message: str, status_code: int | None = None) -> None:
super().__init__(message)
self.status_code = status_code
def test_map_error_status_code_auth() -> None:
"""401 errors should map to authentication failures."""
mapped = map_error(DummyError("auth failed", status_code=401), provider="openai")
assert isinstance(mapped, LLMAuthenticationError)
def test_map_error_status_code_rate_limit() -> None:
"""429 errors should map to rate limit failures."""
mapped = map_error(DummyError("rate limited", status_code=429), provider="openai")
assert isinstance(mapped, LLMRateLimitError)
def test_map_error_message_context_window() -> None:
"""Context length errors should map to the provider context window error."""
mapped = map_error(DummyError("maximum context length exceeded"), provider="openai")
assert isinstance(mapped, ProviderContextWindowError)
def test_map_error_falls_back_to_api_error() -> None:
"""Unknown errors should fall back to generic API error mapping."""
mapped = map_error(DummyError("boom", status_code=500), provider="openai")
assert isinstance(mapped, LLMAPIError)
assert mapped.status_code == 500