ForcePilot/backend/test/unit/channel/transport/test_protocol.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

54 lines
1.4 KiB
Python

from __future__ import annotations
from collections.abc import Callable
from yuxi.channel.transport.protocol import MessageHandler, Transport, TransportState
class TestTransportState:
def test_enum_values(self):
assert TransportState.DISCONNECTED == "disconnected"
assert TransportState.CONNECTING == "connecting"
assert TransportState.CONNECTED == "connected"
assert TransportState.RECONNECTING == "reconnecting"
assert TransportState.STOPPED == "stopped"
def test_is_str_enum(self):
assert isinstance(TransportState.CONNECTED, str)
class _FakeTransport:
@property
def state(self) -> TransportState:
return TransportState.CONNECTED
async def start(self) -> None:
pass
async def stop(self) -> None:
pass
def on_message(self, handler: MessageHandler) -> None:
pass
async def send(self, data: bytes | str) -> None:
pass
class _MissingTransport:
pass
class TestTransportProtocol:
def test_runtime_checkable_accepts_complete_implementation(self):
assert isinstance(_FakeTransport(), Transport)
def test_runtime_checkable_rejects_incomplete_implementation(self):
assert not isinstance(_MissingTransport(), Transport)
def test_message_handler_type(self):
async def handler(raw: bytes) -> None:
pass
assert isinstance(handler, Callable)