ForcePilot/backend/test/unit/channel/startup/test_domain_exceptions.py
Kris 6c95dc006a test: 新增渠道模块全链路单元测试用例与目录结构
完成渠道模块的单元测试目录搭建,新增多个领域模型、端口、中间件、事件、服务以及基础设施层的单元测试文件,同时补充了conftest.py的环境变量配置,完善测试基础环境。
2026-05-30 21:55:35 +08:00

69 lines
2.2 KiB
Python

from __future__ import annotations
import pytest
from yuxi.channel.domain.exception.agent_crash_error import AgentCrashError
from yuxi.channel.domain.exception.recoverable_error import RecoverableError
from yuxi.channel.domain.exception.unrecoverable_error import UnrecoverableError
from yuxi.channel.domain.exception.channel_error import ChannelError
from yuxi.channel.domain.exception.abort_mapping import AbortMapping
class TestAgentCrashError:
def test_creation(self):
error = AgentCrashError("agent crashed")
assert str(error) == "agent crashed"
assert error.message == "agent crashed"
def test_creation_with_details(self):
error = AgentCrashError("agent crashed", details={"agent_id": "1"})
assert error.details == {"agent_id": "1"}
class TestRecoverableError:
def test_creation(self):
error = RecoverableError("temporary failure")
assert str(error) == "temporary failure"
assert error.message == "temporary failure"
def test_creation_with_retry_after(self):
error = RecoverableError("temporary failure", retry_after=5)
assert error.retry_after == 5
class TestUnrecoverableError:
def test_creation(self):
error = UnrecoverableError("permanent failure")
assert str(error) == "permanent failure"
assert error.message == "permanent failure"
class TestChannelError:
def test_creation(self):
error = ChannelError("channel error")
assert str(error) == "channel error"
assert error.message == "channel error"
def test_creation_with_code(self):
error = ChannelError("channel error", code="CHANNEL_ERROR")
assert error.code == "CHANNEL_ERROR"
class TestAbortMapping:
def test_creation(self):
mapping = AbortMapping(
code="AUTH_FAILED",
reason="Authentication failed",
status_code=401,
)
assert mapping.code == "AUTH_FAILED"
assert mapping.reason == "Authentication failed"
assert mapping.status_code == 401
def test_default_status_code(self):
mapping = AbortMapping(
code="TEST",
reason="Test",
)
assert mapping.status_code == 400