Files
OperationRoomMonitor/tests/test_visualize_parse.py

62 lines
2.2 KiB
Python
Raw Permalink Normal View History

2026-06-04 16:44:29 +08:00
"""visualize_pipeline TSV 解析单元测试(无需 GPU"""
from __future__ import annotations
import sys
from pathlib import Path
PACK_ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(PACK_ROOT / "scripts"))
from visualize_tsv import parse_result_tsv # noqa: E402
def test_parse_offline_12col_with_doctor_summary(tmp_path: Path) -> None:
tsv = tmp_path / "r.txt"
tsv.write_text(
"rank\tstart_sec\tend_sec\tproduct_id_top1\ttop1_name\ttop1_conf\t"
"product_id_top2\ttop2_name\ttop2_conf\tproduct_id_top3\ttop3_name\ttop3_conf\n"
"1\t1.0\t5.0\tP1\t手套\t0.9\t\t\t\t\t\t\n"
"医生信息:张三 (id=D01, conf=0.91)\n",
encoding="utf-8",
)
segs, doc = parse_result_tsv(tsv)
assert len(segs) == 1
assert segs[0].row.n1 == "手套"
assert doc is not None and "张三" in doc
def test_parse_stream_15col(tmp_path: Path) -> None:
tsv = tmp_path / "s.txt"
header = "\t".join(
[
"rank", "start_sec", "end_sec", "product_id_top1", "top1_name", "top1_conf",
"product_id_top2", "top2_name", "top2_conf", "product_id_top3", "top3_name", "top3_conf",
"doctor_id", "doctor_name", "doctor_conf",
]
)
row = [
"1", "2.0", "8.0", "",
"(无有效耗材帧:好帧/白名单/耗材置信度未全部满足)", "",
"", "", "", "", "", "", "D2", "李四", "0.77",
]
tsv.write_text(header + "\n" + "\t".join(row) + "\n", encoding="utf-8")
segs, doc = parse_result_tsv(tsv)
assert len(segs) == 1
assert segs[0].is_failure()
assert segs[0].doctor_name == "李四"
assert doc is None
def test_parse_failure_hud_text(tmp_path: Path) -> None:
tsv = tmp_path / "f.txt"
tsv.write_text(
"rank\tstart_sec\tend_sec\tproduct_id_top1\ttop1_name\ttop1_conf\t"
"product_id_top2\ttop2_name\ttop2_conf\tproduct_id_top3\ttop3_name\ttop3_conf\n"
"1\t0.5\t3.0\t\t(无有效耗材帧:好帧/白名单/耗材置信度未全部满足)\t\t"
"\t\t\t\t\t\t\n",
encoding="utf-8",
)
segs, _ = parse_result_tsv(tsv)
assert segs[0].is_failure()
assert "无有效耗材帧" in segs[0].row.n1