Files
lyxy-document/openspec/specs/test-runner/spec.md
lanyuanxiaoyao 89ffc88082 fix: 优化配置、修复测试和 temp_pdf 中文字体支持
- 优化 config.py,为所有依赖添加版本号,为所有文件类型添加 Darwin-x86_64 配置
- 修改 run_tests.py,添加平台相关 TEST_FIXTURE_DEPENDENCIES,简化 cli 和 all 测试逻辑
- 修复 tests/conftest.py 中 temp_pdf 的中文字体支持,使用 macOS 系统字体
- 更新 tests/test_core/test_advice_generator.py 以适应 Python 3.12 的默认配置
- 更新 openspec 相关规格文档
2026-03-17 10:50:48 +08:00

70 lines
2.8 KiB
Markdown
Raw 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.
# Test Runner Specification
## Purpose
定义自动化测试运行器的功能规范包括测试类型选择、依赖自动加载、pytest 参数透传等。
## Requirements
### Requirement: 测试运行器支持指定测试类型
测试运行器 SHALL 支持通过命令行参数指定测试类型,自动加载对应依赖并运行 pytest。
#### Scenario: 运行 PDF 测试
- **WHEN** 用户执行 `python run_tests.py pdf`
- **THEN** 自动加载 config.DEPENDENCIES["pdf"] 中的依赖
- **AND** 自动加载测试 fixtures 所需的依赖
- **AND** 运行 tests/test_readers/test_pdf/ 目录下的测试
#### Scenario: 运行 DOCX 测试
- **WHEN** 用户执行 `python run_tests.py docx`
- **THEN** 自动加载 config.DEPENDENCIES["docx"] 中的依赖
- **AND** 自动加载测试 fixtures 所需的依赖
- **AND** 运行 tests/test_readers/test_docx/ 目录下的测试
#### Scenario: 运行 CLI 测试(无特殊依赖)
- **WHEN** 用户执行 `python run_tests.py cli`
- **THEN** 加载 pytest 依赖
- **AND** 自动加载测试 fixtures 所需的依赖
- **AND** 加载 config.DEPENDENCIES 中所有类型的依赖(去重)
- **AND** 运行 tests/test_cli/ 目录下的测试
#### Scenario: 运行所有测试
- **WHEN** 用户执行 `python run_tests.py all`
- **THEN** 加载 config.DEPENDENCIES 中所有类型的依赖(去重)
- **AND** 自动加载测试 fixtures 所需的依赖
- **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"