45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
"""cloud_voice_dialog_v1 短语与 confirm 解析。"""
|
|
from voice_drone.core.cloud_dialog_v1 import (
|
|
match_phrase_list,
|
|
normalize_phrase_text,
|
|
parse_confirm_dict,
|
|
)
|
|
|
|
|
|
def test_normalize():
|
|
assert normalize_phrase_text(" a b ") == "a b"
|
|
|
|
|
|
def test_match_phrases():
|
|
assert match_phrase_list(normalize_phrase_text("确认"), ["确认"])
|
|
assert match_phrase_list(normalize_phrase_text("取消"), ["取消"])
|
|
assert match_phrase_list(normalize_phrase_text("好的确认"), ["确认"])
|
|
# 复述长提示:不应仅因子串「取消」命中
|
|
long_prompt = normalize_phrase_text("请回复确认或取消")
|
|
assert match_phrase_list(long_prompt, ["取消"]) is False
|
|
assert match_phrase_list(long_prompt, ["确认"]) is False
|
|
|
|
|
|
def test_parse_confirm_ok():
|
|
d = parse_confirm_dict(
|
|
{
|
|
"required": True,
|
|
"timeout_sec": 10,
|
|
"confirm_phrases": ["确认"],
|
|
"cancel_phrases": ["取消"],
|
|
"pending_id": "p1",
|
|
}
|
|
)
|
|
assert d is not None
|
|
assert d["required"] is True
|
|
assert d["timeout_sec"] == 10.0
|
|
assert "确认" in d["confirm_phrases"]
|
|
|
|
|
|
def test_parse_confirm_reject_bad_required():
|
|
assert parse_confirm_dict({"required": "yes"}) is None
|
|
|
|
|
|
def test_cancel_priority_concept():
|
|
assert match_phrase_list(normalize_phrase_text("取消"), ["取消"])
|