- 新增 Alembic 初始迁移、领域明细模型及归档持久化与重试链路\n- 拆分视频会话注册表、分类处理、推理时间窗聚合与流处理\n- 消耗日志:TSV/Markdown 含 top2/top3;item_id 优先产品编码;待确认记「待确认」行,语音确认后落正式行并更新汇总\n- 待确认时内存/DB 明细为占位行,确认后替换;拒绝时移除占位\n- 分类 probs 先 detach/cpu 再转 NumPy,修复 MPS/CUDA 上推理被静默跳过\n- 补充集成测试、归档与设备张量等单测 Made-with: Cursor
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""effective_candidate_consumables:空请求时回退到目录或模型类名。"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from pathlib import Path
|
||
from unittest.mock import MagicMock
|
||
|
||
import pytest
|
||
from openpyxl import Workbook
|
||
|
||
from app.config import Settings
|
||
from app.services.consumable_vision_algorithm import ConsumableVisionAlgorithmService
|
||
|
||
|
||
def test_effective_preserves_non_empty_request() -> None:
|
||
svc = ConsumableVisionAlgorithmService(Settings())
|
||
got = svc.effective_candidate_consumables([" 纱布 ", "缝线", "纱布"])
|
||
assert got == ["纱布", "缝线"]
|
||
|
||
|
||
def test_effective_empty_uses_model_class_names(monkeypatch: pytest.MonkeyPatch) -> None:
|
||
svc = ConsumableVisionAlgorithmService(Settings())
|
||
mock_cls = MagicMock()
|
||
mock_cls.names = {0: "ban", 1: "apple"}
|
||
monkeypatch.setattr(svc, "_get_cls", lambda: mock_cls)
|
||
assert svc.effective_candidate_consumables([]) == ["apple", "ban"]
|
||
|
||
|
||
def test_effective_empty_prefers_catalog_xlsx(tmp_path: Path) -> None:
|
||
xlsx = tmp_path / "cat.xlsx"
|
||
wb = Workbook()
|
||
ws = wb.active
|
||
ws.append(["产品编码", "商品名称"])
|
||
ws.append(["C1", "商品乙"])
|
||
ws.append(["C2", "商品甲"])
|
||
wb.save(xlsx)
|
||
|
||
settings = Settings(consumable_catalog_xlsx_path=str(xlsx))
|
||
svc = ConsumableVisionAlgorithmService(settings)
|
||
got = svc.effective_candidate_consumables([])
|
||
assert got == ["商品乙", "商品甲"]
|
||
|
||
|
||
def test_effective_whitespace_only_treated_as_empty(
|
||
monkeypatch: pytest.MonkeyPatch,
|
||
) -> None:
|
||
svc = ConsumableVisionAlgorithmService(Settings())
|
||
mock_cls = MagicMock()
|
||
mock_cls.names = {0: "x"}
|
||
monkeypatch.setattr(svc, "_get_cls", lambda: mock_cls)
|
||
assert svc.effective_candidate_consumables(["", " "]) == ["x"]
|