- desktopauto:cardocr 引擎/流水线/校验与 ocr 调整,sdk.json/pyproject/版本三处一致 - dingtalk:AI 表格读写与错误封装扩充 - aitable:client/cli/自测与打包配置更新
60 lines
2.4 KiB
Python
60 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""SDK 安装冒烟:纯离线校验导入与识图算法,不碰真实桌面 / 窗口 / 进程 / OCR。
|
||
|
||
由 sdk.json.selftest 声明,执行机安装 SDK 后运行 main();
|
||
开发态全量自测仍用库根 libs/desktopauto/_selftest.py(会检查窗口、进程、OCR 等)。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import numpy as np
|
||
|
||
from . import matcher
|
||
|
||
EXPECTED_VERSION = "0.5.3"
|
||
|
||
#: 插件实际用到的门面 API,缺失即视为破坏性变更
|
||
REQUIRED_EXPORTS = (
|
||
"Screen", "find", "find_all", "exists", "click", "click_at", "hotkey",
|
||
"paste", "screenshot", "find_windows", "get_window", "Window",
|
||
"mark", "summarize", "ocr", "fs", "keys", "sleep",
|
||
"cardocr", "ocr_card", "ocr_cards",
|
||
)
|
||
|
||
|
||
def main() -> int:
|
||
import desktopauto
|
||
|
||
version = str(getattr(desktopauto, "__version__", ""))
|
||
if version != EXPECTED_VERSION:
|
||
raise AssertionError(f"版本不一致:__version__={version},期望 {EXPECTED_VERSION}")
|
||
|
||
missing = [n for n in REQUIRED_EXPORTS if not hasattr(desktopauto, n)]
|
||
if missing:
|
||
raise AssertionError(f"门面 API 缺失:{missing}")
|
||
|
||
# 合成图 + 同款模板:只跑内存里的匹配算法,不截图、不点击
|
||
img = np.full((120, 200, 3), 240, dtype=np.uint8)
|
||
img[20:50, 30:90] = (40, 120, 200)
|
||
tpl = img[20:50, 30:90].copy()
|
||
hits = matcher.match_in(img, tpl, threshold=0.9)
|
||
if not any(h.left == 30 and h.top == 20 for h in hits):
|
||
raise AssertionError(f"识图未命中预期坐标:{[(h.left, h.top) for h in hits]}")
|
||
hit = hits[0]
|
||
if hit.center != (hit.left + 30, hit.top + 15):
|
||
raise AssertionError(f"中心点换算错误:{hit.center}")
|
||
|
||
# 证件照识别:只校验纯算法(不加载 OCR 模型、不读图片)
|
||
from .cardocr import match, validators # noqa: PLC0415
|
||
|
||
if not validators.id_checksum_ok("530425198904041120"):
|
||
raise AssertionError("身份证校验码算法异常")
|
||
if not validators.luhn_ok("6214833831445443"):
|
||
raise AssertionError("银行卡 Luhn 算法异常")
|
||
runs = ["6214832337534461", "621483237534461"]
|
||
cov, status, _ = match.coverage("6214832377534461", runs, id_digits="530425198904041120")
|
||
if status not in ("strong", "exact") or cov < 0.85:
|
||
raise AssertionError(f"卡号命中分析异常:cov={cov:.2f} status={status}")
|
||
|
||
print(f"[OK] desktopauto {version} SDK 冒烟通过({len(REQUIRED_EXPORTS)} 项门面 API)")
|
||
return 0
|