feat(protocols): implement tv_core transport protocols and frozen result models
- Implement WebSocketClosedError preserving Exception.args and str() representation - Implement frozen TvStatus, TvStateSnapshot, CaptureResult, KeysResult, and TextResult dataclasses - Remove Red-phase xfail markers in tests/test_protocols.py
This commit is contained in:
1 parent
712aff354b
commit
72745b85d4
2 files changed
+4
-21
No files matched your search
@@ -8,11 +8,11 @@ from typing import Any, Literal, Protocol
|
||||
class WebSocketClosedError(Exception):
|
||||
"""Raised when a WebSocket transport closes unexpectedly or is already closed."""
|
||||
|
||||
code: int
|
||||
reason: str
|
||||
|
||||
def __init__(self, code: int, reason: str = "") -> None:
|
||||
raise NotImplementedError
|
||||
message = f"WebSocket closed ({code}): {reason}" if reason else f"WebSocket closed ({code})"
|
||||
super().__init__(message)
|
||||
self.code = code
|
||||
self.reason = reason
|
||||
|
||||
|
||||
class WebSocketTransport(Protocol):
|
||||
@@ -61,9 +61,6 @@ class TvStatus:
|
||||
status: Literal["connected", "already_connected"]
|
||||
elapsed_ms: int
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class TvStateSnapshot:
|
||||
@@ -77,9 +74,6 @@ class TvStateSnapshot:
|
||||
foreground_app: str | None
|
||||
last_updated: float | None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class CaptureResult:
|
||||
@@ -90,9 +84,6 @@ class CaptureResult:
|
||||
changed_since_last: bool
|
||||
size_bytes: int
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class KeysResult:
|
||||
@@ -105,9 +96,6 @@ class KeysResult:
|
||||
size_bytes: int | None = None
|
||||
capture_error: str | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
raise NotImplementedError
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class TextResult:
|
||||
@@ -119,6 +107,3 @@ class TextResult:
|
||||
changed_since_last: bool | None = None
|
||||
size_bytes: int | None = None
|
||||
capture_error: str | None = None
|
||||
|
||||
def __post_init__(self) -> None:
|
||||
raise NotImplementedError
|
||||
@@ -12,7 +12,6 @@ from lg_smtv_mcp.tv_core.protocols import (
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True, reason="Red phase: protocols")
|
||||
def test_websocket_closed_error_preserves_args_and_str_representation() -> None:
|
||||
err = WebSocketClosedError(1008, "Try Again Later (EWS)")
|
||||
|
||||
@@ -29,7 +28,6 @@ def test_websocket_closed_error_preserves_args_and_str_representation() -> None:
|
||||
assert "1000" in str(err_no_reason)
|
||||
|
||||
|
||||
@pytest.mark.xfail(strict=True, reason="Red phase: protocols")
|
||||
def test_result_dataclasses_are_frozen_and_expose_expected_fields() -> None:
|
||||
status = TvStatus(status="connected", elapsed_ms=120)
|
||||
snapshot = TvStateSnapshot(
|
||||
|
||||
Reference in new issue
Block a user