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"}