85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
|
|
"""提示词模块单元测试。"""
|
||
|
|
|
||
|
|
from prompts import (
|
||
|
|
SYSTEM_PROMPT_TEMPLATE,
|
||
|
|
USER_PROMPT_TEMPLATE,
|
||
|
|
get_system_prompt,
|
||
|
|
get_user_prompt,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
class TestSystemPromptTemplate:
|
||
|
|
"""系统提示词模板测试。"""
|
||
|
|
|
||
|
|
def test_contains_delimiter_placeholder(self):
|
||
|
|
assert "{delimiter}" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
def test_contains_semantic_completeness_rule(self):
|
||
|
|
assert "语义完整性" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
def test_contains_self_contained_rule(self):
|
||
|
|
assert "自包含性" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
def test_contains_heading_preservation_rule(self):
|
||
|
|
assert "标题层级保留" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
def test_contains_table_integrity_rule(self):
|
||
|
|
assert "表格完整性" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
def test_contains_granularity_rule(self):
|
||
|
|
assert "合理粒度" in SYSTEM_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
|
||
|
|
class TestUserPromptTemplate:
|
||
|
|
"""用户提示词模板测试。"""
|
||
|
|
|
||
|
|
def test_contains_text_content_placeholder(self):
|
||
|
|
assert "{text_content}" in USER_PROMPT_TEMPLATE
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetSystemPrompt:
|
||
|
|
"""get_system_prompt 函数测试。"""
|
||
|
|
|
||
|
|
def test_default_delimiter(self):
|
||
|
|
result = get_system_prompt()
|
||
|
|
assert "---" in result
|
||
|
|
assert "{delimiter}" not in result
|
||
|
|
|
||
|
|
def test_custom_delimiter(self):
|
||
|
|
result = get_system_prompt("===SPLIT===")
|
||
|
|
assert "===SPLIT===" in result
|
||
|
|
assert "{delimiter}" not in result
|
||
|
|
|
||
|
|
def test_delimiter_appears_in_format_example(self):
|
||
|
|
result = get_system_prompt("***")
|
||
|
|
# 分隔符应出现在格式说明和示例中
|
||
|
|
assert "`***`" in result
|
||
|
|
|
||
|
|
def test_empty_delimiter(self):
|
||
|
|
result = get_system_prompt("")
|
||
|
|
assert "{delimiter}" not in result
|
||
|
|
|
||
|
|
|
||
|
|
class TestGetUserPrompt:
|
||
|
|
"""get_user_prompt 函数测试。"""
|
||
|
|
|
||
|
|
def test_text_content_substitution(self):
|
||
|
|
result = get_user_prompt("这是一段测试文本。")
|
||
|
|
assert "这是一段测试文本。" in result
|
||
|
|
assert "{text_content}" not in result
|
||
|
|
|
||
|
|
def test_preserves_surrounding_markers(self):
|
||
|
|
result = get_user_prompt("内容")
|
||
|
|
assert "---开始---" in result
|
||
|
|
assert "---结束---" in result
|
||
|
|
|
||
|
|
def test_multiline_content(self):
|
||
|
|
content = "第一行\n第二行\n第三行"
|
||
|
|
result = get_user_prompt(content)
|
||
|
|
assert content in result
|
||
|
|
|
||
|
|
def test_empty_content(self):
|
||
|
|
result = get_user_prompt("")
|
||
|
|
assert "{text_content}" not in result
|
||
|
|
assert "---开始---" in result
|