51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
|
|
"""口述规则归一与 memoir 入口行为。"""
|
||
|
|
|
||
|
|
from unittest.mock import patch
|
||
|
|
|
||
|
|
from app.features.memoir.oral_normalize import (
|
||
|
|
apply_oral_normalization_rules,
|
||
|
|
normalize_oral_for_memoir,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def test_apply_rules_mei_kanshang_wo() -> None:
|
||
|
|
assert "没看上我" in apply_oral_normalization_rules("我去试镜了 美看上我 张伟")
|
||
|
|
|
||
|
|
|
||
|
|
def test_apply_rules_mei_kanshang_ni() -> None:
|
||
|
|
assert apply_oral_normalization_rules("美看上你") == "没看上你"
|
||
|
|
|
||
|
|
|
||
|
|
def test_apply_rules_no_false_positive_rong() -> None:
|
||
|
|
"""「美容」等不应被误替换。"""
|
||
|
|
s = "我去了解美容项目"
|
||
|
|
assert apply_oral_normalization_rules(s) == s
|
||
|
|
|
||
|
|
|
||
|
|
def test_normalize_respects_global_off() -> None:
|
||
|
|
raw = "美看上我"
|
||
|
|
with patch("app.features.memoir.oral_normalize.settings") as m:
|
||
|
|
m.memoir_oral_normalize_enabled = False
|
||
|
|
m.memoir_oral_normalize_mode = "rules"
|
||
|
|
assert normalize_oral_for_memoir(raw, llm=None) == raw
|
||
|
|
|
||
|
|
|
||
|
|
def test_normalize_rules_mode_no_llm() -> None:
|
||
|
|
raw = "美看上我"
|
||
|
|
with patch("app.features.memoir.oral_normalize.settings") as m:
|
||
|
|
m.memoir_oral_normalize_enabled = True
|
||
|
|
m.memoir_oral_normalize_mode = "rules"
|
||
|
|
m.memoir_oral_normalize_llm_max_tokens = 512
|
||
|
|
m.memoir_oral_normalize_llm_max_input_chars = 8000
|
||
|
|
assert normalize_oral_for_memoir(raw, llm=None) == "没看上我"
|
||
|
|
|
||
|
|
|
||
|
|
def test_normalize_mode_off_string() -> None:
|
||
|
|
raw = "美看上我"
|
||
|
|
with patch("app.features.memoir.oral_normalize.settings") as m:
|
||
|
|
m.memoir_oral_normalize_enabled = True
|
||
|
|
m.memoir_oral_normalize_mode = "off"
|
||
|
|
m.memoir_oral_normalize_llm_max_tokens = 512
|
||
|
|
m.memoir_oral_normalize_llm_max_input_chars = 8000
|
||
|
|
assert normalize_oral_for_memoir(raw, llm=None) == raw
|