54 lines
1.4 KiB
Python
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)
|