Files
operating-room-monitor-server/tests/test_effective_candidate_consumables.py
Kevin 3d7bd70355 feat: 手术视频消耗、待确认与持久化改造
- 新增 Alembic 初始迁移、领域明细模型及归档持久化与重试链路\n- 拆分视频会话注册表、分类处理、推理时间窗聚合与流处理\n- 消耗日志:TSV/Markdown 含 top2/top3;item_id 优先产品编码;待确认记「待确认」行,语音确认后落正式行并更新汇总\n- 待确认时内存/DB 明细为占位行,确认后替换;拒绝时移除占位\n- 分类 probs 先 detach/cpu 再转 NumPy,修复 MPS/CUDA 上推理被静默跳过\n- 补充集成测试、归档与设备张量等单测

Made-with: Cursor
2026-04-23 20:42:21 +08:00

52 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""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"]