semantic_logic.py 模块SemanticLogicReviewer 类ReviewResult 类型对象construction_review/ai_review_engine.py 中的 423-482 行业务逻辑移动到 semantic_logic.pycheck_semantic_logic 函数中引用新模块construction_review/ai_review_engine.py 中的代码test_semantic_logic.pySemantic_Logic_Test/
├── test_semantic_logic.py # 主测试文件(15个测试用例)
├── test_data.py # 测试数据示例
├── conftest.py # pytest 配置和 fixtures
├── pytest.ini # pytest 配置文件
├── requirements_test.txt # 测试依赖
├── run_tests.bat # Windows 测试运行脚本
├── run_tests.py # Python 测试运行脚本
├── README.md # 测试文档
└── SUMMARY.md # 本总结文档
pip install -r Semantic_Logic_Test/requirements_test.txt
# 方式1:使用 pytest 直接运行
pytest Semantic_Logic_Test/test_semantic_logic.py -v
# 方式2:使用 Python 脚本
python Semantic_Logic_Test/run_tests.py
# 方式3:使用 Windows 批处理脚本
Semantic_Logic_Test\run_tests.bat
pytest Semantic_Logic_Test/test_semantic_logic.py --cov=core.construction_review.component.reviewers.semantic_logic --cov-report=html
# 模型配置
SEMANTIC_LOGIC_MODEL_CONFIG = {
"base_url": "http://192.168.91.253:8003/v1",
"api_key": "sk-123456",
"model": "qwen3-30b",
"temperature": 0.7,
"max_tokens": 2000
}
# 使用 AsyncOpenAI 客户端
self.client = AsyncOpenAI(
base_url=SEMANTIC_LOGIC_MODEL_CONFIG["base_url"],
api_key=SEMANTIC_LOGIC_MODEL_CONFIG["api_key"]
)
# 构造提示词参数
prompt_kwargs = {
"review_content": review_content,
"review_references": review_references or ""
}
# 获取提示词模板
prompt_template = prompt_loader.get_prompt_template(
"basic",
"semantic_logic_check",
**prompt_kwargs
)
# 推送审查完成信息
if state and state.get("progress_manager"):
review_result_data = {
'name': 'semantic_logic_check',
'success': result.success,
'details': result.details,
'error_message': result.error_message,
'execution_time': result.execution_time,
'timestamp': time.time()
}
asyncio.create_task(
state["progress_manager"].update_stage_progress(
callback_task_id=state["callback_task_id"],
stage_name=stage_name,
current=None,
status="processing",
message=f"semantic_logic_check 审查完成,耗时: {result.execution_time:.2f}s",
issues=[review_result_data],
event_type="processing"
)
)
# 使用 ReviewResult 对象
result = ReviewResult(
success=True,
details={
"name": "semantic_logic_check",
"response": model_response
},
error_message=None,
execution_time=execution_time
)
unittest.mock 模拟 OpenAI API 调用AsyncMock 模拟异步操作@pytest.mark.asyncio 装饰器AsyncMock 模拟异步函数预期测试结果:
集成测试需要实际 API
网络依赖
增加更多测试场景
改进错误处理
优化性能
如有问题或建议,请联系开发团队。
创建日期: 2025-12-29
版本: 1.0.0
状态: ✅ 完成