Files
operating-room-monitor-server/tests/test_tear_gated_segment_consumption.py
Kevin 8a4bad99d3 feat: 配置写死与 baked 模块,Alembic 建表,百度仅 BAIDU_*
- 新增 app/baked/algorithm|pipeline,非部署参数不再走 env;Settings 保留 DB/HTTP/RTSP/海康/百度/MinIO/Demo
- 移除 init_db_schema 与 reload 配置;main 仅 check_database;start*.sh 在 uvicorn 前执行 alembic upgrade head
- 依赖 psycopg[binary] 供 Alembic 同步 URL;alembic/env 注释与预发清单更新
- 撕段门控消费管线、各视频/语音/归档调用改为 baked
- 百度环境变量仅 BAIDU_APP_ID、BAIDU_API_KEY、BAIDU_SECRET_KEY 与 BAIDU_* 超时/ASR;人脸脚本与 baidu_speech 文案同步
- 全量单测与 .env.example 更新;.gitignore 忽略 refs/(本地权重/视频不入库)

Made-with: Cursor
2026-04-24 15:33:22 +08:00

71 lines
2.2 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.
"""撕段门控 + 段合并的纯逻辑单测(不加载 YOLO"""
from __future__ import annotations
import numpy as np
import pytest
from app.services.tear_gated_segment_consumption.product_map import (
load_tear_segment_name_to_id,
resolve_tear_segment_labels_yaml_path,
)
from app.services.tear_gated_segment_consumption.runner import haocai_mean_topk
from app.services.tear_gated_segment_consumption.segments import merge_tear_segments
def test_merge_tear_segments_one_valid() -> None:
dt = 0.04
rows: list[tuple[int, float, bool, str]] = [
(i, i * dt, True, "A") for i in range(40)
]
segs = merge_tear_segments(
rows,
min_tear_sec=1.2,
min_gap_sec=1.0,
)
assert len(segs) == 1
assert segs[0]["start_frame"] == 0
assert segs[0]["end_frame"] == 39
def test_haocai_mean_topk() -> None:
names = {0: "A", 1: "B"}
a = np.array([0.2, 0.8, 0.0], dtype=np.float32)
b = np.array([0.2, 0.8, 0.0], dtype=np.float32)
t1, c1, t2, c2, t3, c3 = haocai_mean_topk([a, b], names)
assert t1 == "B"
assert abs(c1 - 0.8) < 1e-5
def test_load_tear_segment_name_to_id_uses_package_yaml() -> None:
p = resolve_tear_segment_labels_yaml_path()
assert p.name == "consumable_classifier_labels.yaml"
m = load_tear_segment_name_to_id()
assert "一次性使用灭菌橡胶外科手套" in m or len(m) >= 1
@pytest.mark.asyncio
async def test_append_confirmed_detail_tear_cooldown_keys() -> None:
"""同 item_id 多段在独立 cooldown_key 下应都能写入。"""
from app.services.video.session_registry import SurgerySessionRegistry, SurgerySessionState
reg = SurgerySessionRegistry()
st = SurgerySessionState(candidate_consumables=["X"], name_to_code={"X": "id1"})
await reg.append_confirmed_detail(
state=st,
item_id="SAME",
item_name="A",
doctor_id="d",
source="tear_segment",
cooldown_key="s1:seg:1",
)
await reg.append_confirmed_detail(
state=st,
item_id="SAME",
item_name="A",
doctor_id="d",
source="tear_segment",
cooldown_key="s1:seg:2",
)
assert len(st.details) == 2