Files
operating-room-monitor-server/backend/tests/reference_bundle_fixtures.py

56 lines
2.0 KiB
Python
Raw Permalink Normal View History

2026-05-22 09:35:41 +08:00
"""Shared fixtures for minimal reference bundle trees in batch/subprocess tests."""
from __future__ import annotations
from pathlib import Path
import yaml
2026-05-27 13:48:27 +08:00
REPO_ROOT = Path(__file__).resolve().parents[1]
REFERENCE_NMS_SOURCE = (
REPO_ROOT / "app" / "algorithm_runner" / "actionformer_release" / "libs" / "utils" / "nms.py"
)
2026-05-22 09:35:41 +08:00
def complete_result_tsv_body() -> str:
return (
"rank\tstart_sec\tend_sec\tproduct_id_top1\ttop1_name\ttop1_conf\n"
"1\t0\t1\tP1\t耗材1\t1.0\n"
"医生信息:测试医生 (id=123, conf=0.99)\n"
)
def write_minimal_reference_bundle(bundle: Path) -> None:
bundle.mkdir(parents=True)
(bundle / "main.py").write_text("# fake\n", encoding="utf-8")
(bundle / "code").mkdir()
(bundle / "code" / "repo_root.py").write_text("# fake\n", encoding="utf-8")
2026-05-27 13:48:27 +08:00
nms_target = bundle / "code" / "actionformer_release" / "libs" / "utils"
nms_target.mkdir(parents=True, exist_ok=True)
if REFERENCE_NMS_SOURCE.is_file():
(nms_target / "nms.py").write_bytes(REFERENCE_NMS_SOURCE.read_bytes())
else:
(nms_target / "nms.py").write_text("# fake nms\n", encoding="utf-8")
weights_dir = bundle / "weights"
weights_dir.mkdir()
(weights_dir / "actionformer_epoch_045.pth.tar").write_bytes(b"fake-ckpt")
2026-05-22 09:35:41 +08:00
(bundle / "configs").mkdir()
(bundle / "configs" / "default_config.yaml").write_text(
yaml.safe_dump(
{
"io": {"video": "", "excel": "", "out": "", "whitelist_json": None},
2026-05-27 13:48:27 +08:00
"weights": {"actionformer": "weights/actionformer_epoch_045.pth.tar"},
2026-05-22 09:35:41 +08:00
"runtime": {"work_dir": None, "keep_work_dir": False, "python": None},
"device": {},
"phase1": {},
"phase2": {},
"classification": {},
"tear_merge": {},
"output": {},
},
allow_unicode=True,
sort_keys=False,
),
encoding="utf-8",
)