- 语音:序数解析(第一个/第二个等)、解析失败计数与 API detail.retry_remaining; 百度 ASR 固定 dev_pid 为普通话;SurgeryPipelineError 支持 extra 并入 HTTP detail。 - Demo:demo 路由与假 RTSP、客户端 index 与 README;BackendResolver 与配置调整。 - 可观测:消耗 TSV 日志、语音文件日志、终端 Markdown 辅助;相关测试与依赖更新。 - 注意:.env 仍被 gitignore,本地密钥不会进入本提交。 Made-with: Cursor
63 lines
2.0 KiB
Python
63 lines
2.0 KiB
Python
"""Tests for voice TSV + emit_voice_event (path + TSV line)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import tempfile
|
|
from pathlib import Path
|
|
|
|
from app.config import Settings
|
|
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() -> None:
|
|
s = Settings()
|
|
s.voice_file_log_path = "logs/voice_{surgery_id}.txt"
|
|
p = resolved_voice_log_path("123456", s)
|
|
assert p.name == "voice_123456.txt"
|
|
assert "logs" in str(p)
|
|
|
|
|
|
def test_init_and_append_tsv() -> None:
|
|
with tempfile.TemporaryDirectory() as d:
|
|
base = Path(d)
|
|
s = Settings()
|
|
s.voice_file_log_enabled = True
|
|
s.voice_file_log_path = str((base / "v_{surgery_id}.txt").resolve())
|
|
init_voice_log_file("999999", s)
|
|
p = resolved_voice_log_path("999999", s)
|
|
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, s)
|
|
assert p.read_text(encoding="utf-8").endswith(line)
|
|
|
|
|
|
def test_emit_voice_event_writes_when_enabled() -> None:
|
|
s = Settings()
|
|
s.voice_file_log_enabled = True
|
|
with tempfile.TemporaryDirectory() as d:
|
|
s.voice_file_log_path = str((Path(d) / "v_{surgery_id}.txt").resolve())
|
|
init_voice_log_file("111111", s)
|
|
emit_voice_event(
|
|
s,
|
|
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", s)
|
|
body = p.read_text(encoding="utf-8")
|
|
assert "纱布" in body
|
|
assert "recognized" in body
|
|
assert "k.wav" in body
|