ForcePilot/backend/test/unit/channel/lifecycle/test_context.py
Kris bab30f2715
Some checks failed
Deploy VitePress site to Pages / build (push) Has been cancelled
Ruff Format Check / Ruff Format & Lint (push) Has been cancelled
Deploy VitePress site to Pages / Deploy (push) Has been cancelled
feat:0715
2026-07-15 12:30:58 +08:00

37 lines
1.1 KiB
Python

from __future__ import annotations
from datetime import datetime
from yuxi.channel.lifecycle.context import ChannelLifecycleContext
class TestChannelLifecycleContext:
def test_default_values(self):
ctx = ChannelLifecycleContext()
assert ctx.last_error is None
assert ctx.reconnect_attempts == 0
assert ctx.last_connected_at is None
assert ctx.last_message_at is None
assert ctx.extra == {}
def test_extra_is_isolated(self):
ctx1 = ChannelLifecycleContext()
ctx2 = ChannelLifecycleContext()
ctx1.extra["key"] = "value"
assert ctx2.extra == {}
def test_set_values(self):
now = datetime.now()
ctx = ChannelLifecycleContext(
last_error="boom",
reconnect_attempts=3,
last_connected_at=now,
last_message_at=now,
extra={"foo": "bar"},
)
assert ctx.last_error == "boom"
assert ctx.reconnect_attempts == 3
assert ctx.last_connected_at == now
assert ctx.last_message_at == now
assert ctx.extra == {"foo": "bar"}