Files
operating-room-monitor-server/tests/test_voice_file_log.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

73 lines
2.2 KiB
Python

"""Tests for voice TSV + emit_voice_event (path + TSV line)."""
from __future__ import annotations
import tempfile
from pathlib import Path
import pytest
from app.baked import pipeline as bp
from app.services.voice_file_log import (
append_voice_tsv_line,
emit_voice_event,
init_voice_log_file,
resolved_voice_log_path,
)
def test_resolved_voice_log_path_replaces_surgery_id(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(bp, "VOICE_FILE_LOG_PATH", "logs/voice_{surgery_id}.txt")
p = resolved_voice_log_path("123456")
assert p.name == "voice_123456.txt"
assert "logs" in str(p)
def test_init_and_append_tsv(monkeypatch: pytest.MonkeyPatch) -> None:
with tempfile.TemporaryDirectory() as d:
base = Path(d)
monkeypatch.setattr(bp, "VOICE_FILE_LOG_ENABLED", True)
monkeypatch.setattr(
bp,
"VOICE_FILE_LOG_PATH",
str((base / "v_{surgery_id}.txt").resolve()),
)
init_voice_log_file("999999")
p = resolved_voice_log_path("999999")
assert p.exists()
h = p.read_text(encoding="utf-8")
assert "来源" in h and "confirmation_id" in h
line = "ts\ttest\trecognized\tcid1\t\t\tfalse\t\tk.wav\n"
append_voice_tsv_line("999999", line)
assert p.read_text(encoding="utf-8").endswith(line)
def test_emit_voice_event_writes_when_enabled(
monkeypatch: pytest.MonkeyPatch,
) -> None:
monkeypatch.setattr(bp, "VOICE_FILE_LOG_ENABLED", True)
with tempfile.TemporaryDirectory() as d:
monkeypatch.setattr(
bp,
"VOICE_FILE_LOG_PATH",
str((Path(d) / "v_{surgery_id}.txt").resolve()),
)
init_voice_log_file("111111")
emit_voice_event(
surgery_id="111111",
source="wav",
status="recognized",
confirmation_id="c1",
asr_text="纱布",
resolved_label="纱布",
rejected=False,
audio_object_key="k.wav",
)
p = resolved_voice_log_path("111111")
body = p.read_text(encoding="utf-8")
assert "纱布" in body
assert "recognized" in body
assert "k.wav" in body