35 lines
1.0 KiB
Python
35 lines
1.0 KiB
Python
import pytest
|
|
|
|
from genesis.inference.exceptions import (
|
|
LLMError,
|
|
LLMNetworkError,
|
|
LLMNotConfiguredError,
|
|
LLMResponseError,
|
|
LLMTimeoutError,
|
|
)
|
|
|
|
|
|
def test_error_hierarchy():
|
|
assert issubclass(LLMNetworkError, LLMError)
|
|
assert issubclass(LLMTimeoutError, LLMError)
|
|
assert issubclass(LLMNotConfiguredError, LLMError)
|
|
assert issubclass(LLMResponseError, LLMError)
|
|
|
|
|
|
def test_error_message_roundtrip():
|
|
e = LLMTimeoutError("timeout!")
|
|
assert str(e) == "timeout!"
|
|
|
|
|
|
def test_error_code_class_attributes():
|
|
# error_code 与 api-design §7 错误码表一一对应(机器可读事实源)
|
|
assert LLMError.error_code is None
|
|
assert LLMTimeoutError.error_code == "LLM_TIMEOUT"
|
|
assert LLMNetworkError.error_code == "LLM_NETWORK_ERROR"
|
|
assert LLMNotConfiguredError.error_code == "LLM_NOT_CONFIGURED"
|
|
assert LLMResponseError.error_code == "LLM_PARSE_ERROR"
|
|
|
|
|
|
def test_error_code_inherited_by_instance():
|
|
e = LLMNetworkError("network")
|
|
assert e.error_code == "LLM_NETWORK_ERROR" |