|
|
1 maand geleden | |
|---|---|---|
| .. | ||
| README.md | 1 maand geleden | |
| SUMMARY.md | 1 maand geleden | |
| conftest.py | 1 maand geleden | |
| pytest.ini | 1 maand geleden | |
| requirements_test.txt | 1 maand geleden | |
| run_tests.bat | 1 maand geleden | |
| run_tests.py | 1 maand geleden | |
| test_data.py | 1 maand geleden | |
| test_semantic_logic.py | 1 maand geleden | |
本测试套件用于测试 core/construction_review/component/reviewers/semantic_logic.py 模块的功能。
确保已安装必要的依赖:
pip install pytest pytest-asyncio pytest-mock
# 在项目根目录下运行
cd /h:/UGit/LQAgentPlatform
# 运行所有测试
pytest Semantic_Logic_Test/test_semantic_logic.py -v
# 运行测试并显示详细输出
pytest Semantic_Logic_Test/test_semantic_logic.py -v -s
# 运行测试并生成覆盖率报告
pytest Semantic_Logic_Test/test_semantic_logic.py --cov=core.construction_review.component.reviewers.semantic_logic --cov-report=html
# 只运行基础功能测试
pytest Semantic_Logic_Test/test_semantic_logic.py::TestSemanticLogicReviewer -v
# 只运行边界情况测试
pytest Semantic_Logic_Test/test_semantic_logic.py::TestEdgeCases -v
# 测试初始化
pytest Semantic_Logic_Test/test_semantic_logic.py::TestSemanticLogicReviewer::test_reviewer_initialization -v
# 测试成功场景
pytest Semantic_Logic_Test/test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_success -v
# 测试错误处理
pytest Semantic_Logic_Test/test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_api_error -v
集成测试需要实际的 API 服务可用,如果不想运行集成测试:
pytest Semantic_Logic_Test/test_semantic_logic.py -v -m "not integration"
============================= test session starts =============================
platform win32 -- Python 3.x.x, pytest-7.x.x, pluggy-1.x.x
collected 15 items
test_semantic_logic.py::TestSemanticLogicReviewer::test_reviewer_initialization PASSED [ 6%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_global_singleton_instance PASSED [ 13%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_model_config PASSED [ 20%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_success PASSED [ 26%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_without_state PASSED [ 33%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_api_error PASSED [ 40%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_empty_content PASSED [ 46%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_check_semantic_logic_with_references PASSED [ 53%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_message_format_conversion PASSED [ 60%]
test_semantic_logic.py::TestSemanticLogicReviewer::test_execution_time_tracking PASSED [ 66%]
test_semantic_logic.py::TestIntegration::test_full_workflow SKIPPED [ 73%]
test_semantic_logic.py::TestEdgeCases::test_very_long_content PASSED [ 80%]
test_semantic_logic.py::TestEdgeCases::test_special_characters PASSED [ 86%]
test_semantic_logic.py::TestEdgeCases::test_unicode_content PASSED [ 93%]
======================== 14 passed, 1 skipped in 2.34s ========================
验证 SemanticLogicReviewer 类是否正确初始化,包括:
模拟正常的语义逻辑检查流程:
验证各种错误场景的处理:
测试极端情况下的系统行为:
测试使用了以下 Mock 对象:
这样可以在不依赖实际 API 服务的情况下进行测试。
@pytest.mark.integration 的测试需要实际的 API 服务,默认会被跳过@pytest.mark.asyncio 装饰器asyncio.sleep() 来模拟延迟,可能需要几秒钟pytest Semantic_Logic_Test/test_semantic_logic.py -v -s --log-cli-level=DEBUG
pytest Semantic_Logic_Test/test_semantic_logic.py --lf
pytest Semantic_Logic_Test/test_semantic_logic.py --pdb
pytest Semantic_Logic_Test/test_semantic_logic.py --html=report.html --self-contained-html
可以将测试集成到 CI/CD 流程中:
# .github/workflows/test.yml 示例
name: Run Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install dependencies
run: |
pip install -r requirements.txt
pip install pytest pytest-asyncio pytest-mock pytest-cov
- name: Run tests
run: pytest Semantic_Logic_Test/test_semantic_logic.py -v --cov
如有问题或建议,请联系开发团队。