From 08299b37dfda86e56e4f2b442f68ccd2da7a82e3 Mon Sep 17 00:00:00 2001 From: 简律纯 Date: Fri, 24 Oct 2025 23:15:35 +0800 Subject: feat: Enhance Processor, RuleExtractor, and Renderers with type hints and improved documentation - Added type hints to Processor methods for better clarity and type safety. - Improved documentation for Processor methods, including detailed descriptions of parameters and return types. - Refactored RuleExtractor to support optional configuration file loading and added error handling for file operations. - Enhanced MarkdownRenderer to handle both list and dictionary inputs, with improved rendering logic. - Created comprehensive examples and tests for all components, ensuring robust functionality and error handling. - Added example rules for D&D 5E and structured output files for various formats (JSON, HTML, Markdown). - Established a testing framework with clear instructions and coverage reporting. --- tests/README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 tests/README.md (limited to 'tests/README.md') diff --git a/tests/README.md b/tests/README.md new file mode 100644 index 0000000..97a8028 --- /dev/null +++ b/tests/README.md @@ -0,0 +1,63 @@ +# ConventionalRP 测试套件 + +本目录包含 ConventionalRP SDK 的所有单元测试。 + +## 测试文件 + +- `test_parser.py` - Parser 解析器测试 +- `test_processor.py` - Processor 处理器测试 +- `test_rule_extractor.py` - RuleExtractor 规则提取器测试 +- `test_renderers.py` - 渲染器测试(HTML/JSON/Markdown) +- `test_pyo3.py` - PyO3 Rust 扩展测试 + +## 运行测试 + +### 运行所有测试 + +```bash +python tests/run_tests.py +``` + +### 运行单个测试文件 + +```bash +python -m unittest tests/test_parser.py +python -m unittest tests/test_processor.py +``` + +### 运行特定测试类 + +```bash +python -m unittest tests.test_parser.TestParser +``` + +### 运行特定测试方法 + +```bash +python -m unittest tests.test_parser.TestParser.test_load_rules_success +``` + +## 测试覆盖率 + +要查看测试覆盖率,请安装 `coverage` 并运行: + +```bash +pip install coverage +coverage run -m unittest discover -s tests -p "test_*.py" +coverage report +coverage html # 生成 HTML 报告 +``` + +## 测试数据 + +测试使用临时文件来模拟规则文件和日志文件,测试完成后会自动清理。 + +## 添加新测试 + +创建新的测试文件时,请遵循以下约定: + +1. 文件名以 `test_` 开头 +2. 测试类继承自 `unittest.TestCase` +3. 测试方法以 `test_` 开头 +4. 使用 `setUp()` 和 `tearDown()` 方法管理测试状态 +5. 添加清晰的文档字符串说明测试目的 -- cgit v1.2.3-70-g09d2