feat: 新增测试运行器脚本 run_tests.py

- 新增根目录 run_tests.py,自动根据测试类型加载依赖
- 支持所有测试类型:pdf/docx/xlsx/pptx/html/xls/doc/ppt/cli/core/utils/all
- 支持透传 pytest 参数(-v/--cov 等)
- 补全 advice_generator.py 中的 DocReader 和 PptReader 映射
- 更新 README.md,简化测试命令说明
This commit is contained in:
2026-03-16 23:14:28 +08:00
parent a490b2642c
commit 675235f5b3
4 changed files with 314 additions and 178 deletions

View File

@@ -0,0 +1,64 @@
# Test Runner Specification
## Purpose
定义自动化测试运行器的功能规范包括测试类型选择、依赖自动加载、pytest 参数透传等。
## Requirements
### Requirement: 测试运行器支持指定测试类型
测试运行器 SHALL 支持通过命令行参数指定测试类型,自动加载对应依赖并运行 pytest。
#### Scenario: 运行 PDF 测试
- **WHEN** 用户执行 `python run_tests.py pdf`
- **THEN** 自动加载 config.DEPENDENCIES["pdf"] 中的依赖
- **AND** 运行 tests/test_readers/test_pdf/ 目录下的测试
#### Scenario: 运行 DOCX 测试
- **WHEN** 用户执行 `python run_tests.py docx`
- **THEN** 自动加载 config.DEPENDENCIES["docx"] 中的依赖
- **AND** 运行 tests/test_readers/test_docx/ 目录下的测试
#### Scenario: 运行 CLI 测试(无特殊依赖)
- **WHEN** 用户执行 `python run_tests.py cli`
- **THEN** 仅加载 pytest 依赖
- **AND** 运行 tests/test_cli/ 目录下的测试
#### Scenario: 运行所有测试
- **WHEN** 用户执行 `python run_tests.py all`
- **THEN** 加载 config.DEPENDENCIES 中所有类型的依赖(去重)
- **AND** 运行 tests/ 目录下的所有测试
### Requirement: 测试运行器支持透传 pytest 参数
测试运行器 SHALL 支持将额外的命令行参数透传给 pytest。
#### Scenario: 传递 -v 参数
- **WHEN** 用户执行 `python run_tests.py pdf -v`
- **THEN** pytest 以 verbose 模式运行
#### Scenario: 传递 --cov 参数
- **WHEN** 用户执行 `python run_tests.py pdf --cov=scripts`
- **THEN** pytest 生成测试覆盖率报告
#### Scenario: 运行特定测试文件
- **WHEN** 用户执行 `python run_tests.py pdf tests/test_readers/test_pdf/test_docling_pdf.py`
- **THEN** 仅运行指定的测试文件
### Requirement: 测试运行器支持平台特定配置
测试运行器 SHALL 根据当前平台自动选择对应的依赖配置(如 Darwin-x86_64
#### Scenario: 在 Darwin-x86_64 平台运行 PDF 测试
- **WHEN** 用户在 Darwin-x86_64 平台执行 `python run_tests.py pdf`
- **THEN** 使用 config.DEPENDENCIES["pdf"]["Darwin-x86_64"] 配置(如果存在)
- **AND** 使用 python 3.12(如配置中指定)
### Requirement: advice_generator 包含完整 Reader 映射
advice_generator.py 中的 _READER_KEY_MAP SHALL 包含所有 Reader 类的映射,包括 DocReader 和 PptReader。
#### Scenario: DocReader 映射存在
- **WHEN** 查询 _READER_KEY_MAP[DocReader]
- **THEN** 返回 "doc"
#### Scenario: PptReader 映射存在
- **WHEN** 查询 _READER_KEY_MAP[PptReader]
- **THEN** 返回 "ppt"