feat: add OCR port family protocols
This commit is contained in:
@@ -199,3 +199,32 @@ class TestGateUpdate:
|
||||
GateUpdate(
|
||||
applied=True, state=GateState.CLOSED, epoch=0, failure_count=-1, retry_after_s=0.0
|
||||
)
|
||||
|
||||
|
||||
class TestOcrPorts:
|
||||
"""M3 三个 OCR Protocol(设计 §3.2): runtime_checkable 结构判定。"""
|
||||
|
||||
def test_ocr_ports_runtime_checkable(self):
|
||||
from polygateway.ports import OcrLayoutPort, OcrTextPort, OcrTransport
|
||||
|
||||
class GoodClient:
|
||||
async def recognize_text(self, image): ...
|
||||
async def parse_layout(self, image): ...
|
||||
|
||||
class GoodTransport:
|
||||
async def recognize_text(self, *, image, source, call_id): ...
|
||||
async def parse_layout(self, *, image, source, call_id): ...
|
||||
async def check_health(self, *, source): ...
|
||||
|
||||
assert isinstance(GoodClient(), OcrTextPort)
|
||||
assert isinstance(GoodClient(), OcrLayoutPort)
|
||||
assert isinstance(GoodTransport(), OcrTransport)
|
||||
|
||||
def test_missing_method_rejected(self):
|
||||
from polygateway.ports import OcrTransport
|
||||
|
||||
class NoHealth:
|
||||
async def recognize_text(self, *, image, source, call_id): ...
|
||||
async def parse_layout(self, *, image, source, call_id): ...
|
||||
|
||||
assert not isinstance(NoHealth(), OcrTransport)
|
||||
|
||||
Reference in New Issue
Block a user