Files
DEMO-AGENT/tests/test_application_form_fill_field_merge.py

112 lines
4.1 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import pytest
from review_agent.application_form_fill.services.field_merge import merge_fields, normalize_field_value, rank_source
def test_normalize_field_value_removes_whitespace():
assert normalize_field_value(" 2-8℃ 保存 \n 有效期12个月 ") == "2-8℃保存有效期12个月"
def test_rank_source_prefers_instructions():
assert rank_source("说明书") < rank_source("产品技术要求")
def test_merge_fields_prefers_instructions_and_marks_conflict():
regex_results = {
"fields": [
{
"key": "storage_condition_and_validity",
"label": "产品储存条件及有效期",
"value": "2-8℃保存有效期12个月",
"source_file": "说明书.txt",
"source_role": "说明书",
"evidence": "产品储存条件及有效期2-8℃保存有效期12个月",
"confidence": 0.75,
},
{
"key": "storage_condition_and_validity",
"label": "产品储存条件及有效期",
"value": "-20℃保存",
"source_file": "产品技术要求.txt",
"source_role": "产品技术要求",
"evidence": "产品储存条件及有效期:-20℃保存",
"confidence": 0.8,
},
]
}
merged, conflicts = merge_fields(regex_results, {"fields": []})
field = merged["storage_condition_and_validity"]
assert field.value == "2-8℃保存有效期12个月"
assert field.has_conflict is True
assert conflicts[0]["selected_value"] == "2-8℃保存有效期12个月"
assert conflicts[0]["conflict_values"][0]["value"] == "-20℃保存"
def test_merge_fields_combines_consistent_values_without_conflict():
regex_results = {
"fields": [
{
"key": "product_name",
"label": "产品名称",
"value": "甲胎蛋白检测试剂盒",
"source_file": "说明书.txt",
"source_role": "说明书",
"evidence": "产品名称:甲胎蛋白检测试剂盒",
"confidence": 0.75,
}
]
}
llm_results = {
"fields": [
{
"key": "product_name",
"label": "产品名称",
"value": "甲胎蛋白 检测试剂盒",
"source_file": "产品技术要求.txt",
"source_role": "产品技术要求",
"evidence": "产品名称:甲胎蛋白 检测试剂盒",
"confidence": 0.9,
}
]
}
merged, conflicts = merge_fields(regex_results, llm_results)
assert merged["product_name"].value == "甲胎蛋白检测试剂盒"
assert merged["product_name"].has_conflict is False
assert conflicts == []
def test_merge_fields_fills_agent_from_applicant_for_now():
regex_results = {
"fields": [
{
"key": "applicant_name",
"label": "注册人名称",
"value": "卡尤迪生物科技宜兴有限公司",
"source_file": "目标产品说明书.docx",
"source_role": "说明书",
"evidence": "生产企业名称:卡尤迪生物科技宜兴有限公司",
"confidence": 0.75,
},
{
"key": "applicant_address",
"label": "注册人住所",
"value": "江苏省宜兴经济技术开发区杏里路10号",
"source_file": "目标产品说明书.docx",
"source_role": "说明书",
"evidence": "生产企业住所江苏省宜兴经济技术开发区杏里路10号",
"confidence": 0.75,
},
]
}
merged, conflicts = merge_fields(regex_results, {"fields": []})
assert merged["agent_name"].value == "卡尤迪生物科技宜兴有限公司"
assert merged["agent_name"].label == "代理人名称"
assert merged["agent_address"].value == "江苏省宜兴经济技术开发区杏里路10号"
assert conflicts == []