style: apply ruff format to OCR modules
This commit is contained in:
@@ -249,14 +249,20 @@ class TestMiddleJsonDefense:
|
||||
self._expect_invalid(_zip_bytes(_middle_bytes([page])))
|
||||
|
||||
def test_bbox_order_invalid(self):
|
||||
self._expect_invalid(_zip_bytes(_middle_bytes([_page([_block("table", (218, 48, 41, 282))])])))
|
||||
self._expect_invalid(
|
||||
_zip_bytes(_middle_bytes([_page([_block("table", (218, 48, 41, 282))])]))
|
||||
)
|
||||
|
||||
def test_bbox_int_degenerate(self):
|
||||
# float 合法但 int() 后宽度为零: 专为 CHS shim 的裁剪路径兜底
|
||||
self._expect_invalid(_zip_bytes(_middle_bytes([_page([_block("table", (1.2, 1.2, 1.8, 5))])])))
|
||||
self._expect_invalid(
|
||||
_zip_bytes(_middle_bytes([_page([_block("table", (1.2, 1.2, 1.8, 5))])]))
|
||||
)
|
||||
|
||||
def test_bbox_non_finite(self):
|
||||
self._expect_invalid(_zip_bytes(_middle_bytes([_page([_block("table", (1, 2, float("inf"), 4))])])))
|
||||
self._expect_invalid(
|
||||
_zip_bytes(_middle_bytes([_page([_block("table", (1, 2, float("inf"), 4))])]))
|
||||
)
|
||||
|
||||
def test_type_missing(self):
|
||||
block = {"bbox": [1, 2, 30, 40], "index": 0}
|
||||
@@ -278,8 +284,13 @@ class TestMiddleJsonDefense:
|
||||
class TestErrorTranslation:
|
||||
@pytest.mark.parametrize(
|
||||
("status", "exc_type"),
|
||||
[(502, TransientError), (429, TransientError), (401, SourceDeadError),
|
||||
(403, SourceDeadError), (404, RequestRejectedError)],
|
||||
[
|
||||
(502, TransientError),
|
||||
(429, TransientError),
|
||||
(401, SourceDeadError),
|
||||
(403, SourceDeadError),
|
||||
(404, RequestRejectedError),
|
||||
],
|
||||
)
|
||||
async def test_http_status(self, status, exc_type):
|
||||
t = _transport_for(_routes(text_resp=httpx.Response(status)))
|
||||
|
||||
@@ -234,9 +234,7 @@ class TestTerminalOutcomes:
|
||||
assert client._selector.outcomes == [] # 坏结果 ≠ 坏服务,不喂健康
|
||||
|
||||
async def test_rejected_with_status_counts_no_attempt(self):
|
||||
client, _, gate = _client(
|
||||
[_src()], [RequestRejectedError("parse failed", status_code=200)]
|
||||
)
|
||||
client, _, gate = _client([_src()], [RequestRejectedError("parse failed", status_code=200)])
|
||||
with pytest.raises(RequestRejectedError):
|
||||
await client.parse_layout(b"jpg")
|
||||
assert gate.successes == [("m1", False)]
|
||||
@@ -378,9 +376,7 @@ class TestAssembly:
|
||||
await client.aclose()
|
||||
|
||||
async def test_non_monkey_provider_rejected(self):
|
||||
env = {
|
||||
k.replace("MONKEY", "GLM"): v for k, v in self._ENV.items()
|
||||
}
|
||||
env = {k.replace("MONKEY", "GLM"): v for k, v in self._ENV.items()}
|
||||
with pytest.raises(ValueError, match="monkey"):
|
||||
OcrClient.from_env("OCR", env=env)
|
||||
|
||||
|
||||
@@ -11,6 +11,12 @@ def test_ocr_public_surface_exported():
|
||||
"""M3 OCR 公共 API 面(设计 §3;transport 结果与 Protocol 不出顶层)。"""
|
||||
import polygateway
|
||||
|
||||
for name in ("OcrClient", "OcrSettings", "OcrTextResult", "OcrLayoutResult", "OcrLayoutElement"):
|
||||
for name in (
|
||||
"OcrClient",
|
||||
"OcrSettings",
|
||||
"OcrTextResult",
|
||||
"OcrLayoutResult",
|
||||
"OcrLayoutElement",
|
||||
):
|
||||
assert hasattr(polygateway, name), name
|
||||
assert name in polygateway.__all__, name
|
||||
|
||||
Reference in New Issue
Block a user