aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/test_processor.py
diff options
context:
space:
mode:
author简律纯 <i@jyunko.cn>2025-10-25 00:30:48 +0800
committer简律纯 <i@jyunko.cn>2025-10-25 00:30:48 +0800
commitcbc653ffd0ea9abf4360623dc7a7651e1a49cc61 (patch)
treeea3c396148158077bae3e77eaa9341f8c1990636 /tests/test_processor.py
parent08299b37dfda86e56e4f2b442f68ccd2da7a82e3 (diff)
downloadconventional_role_play-cbc653ffd0ea9abf4360623dc7a7651e1a49cc61.tar.gz
conventional_role_play-cbc653ffd0ea9abf4360623dc7a7651e1a49cc61.zip
feat: Implement plugin system with combat tracker and dice analyzer
- Added `plugin_system_demo.py` to demonstrate basic plugin usage, processing, and analysis. - Created `CombatTrackerPlugin` for tracking combat statistics including damage and healing. - Developed `DiceAnalyzerPlugin` for analyzing dice rolls and calculating success rates. - Introduced `renderer_demo.py` for rendering output in HTML, Markdown, and JSON formats. - Implemented `rule_system_demo.py` to showcase rule engine capabilities with various examples. - Established core rule engine functionality in `rules.py` with support for conditions and actions. - Enhanced base plugin structure in `base.py` to support different plugin types (Processor, Renderer, Analyzer). - Added custom exception handling in `exceptions.py` for better error management. - Configured logging setup in `logging_config.py` for improved logging capabilities. - Created unit tests in `test_rust_core.py` to validate core functionalities and performance.
Diffstat (limited to 'tests/test_processor.py')
-rw-r--r--tests/test_processor.py22
1 files changed, 2 insertions, 20 deletions
diff --git a/tests/test_processor.py b/tests/test_processor.py
index c08fc52..adaf2db 100644
--- a/tests/test_processor.py
+++ b/tests/test_processor.py
@@ -1,17 +1,9 @@
-#!/usr/bin/env python3
-"""
-Processor 模块单元测试
-"""
-
import unittest
from conventionalrp.core.processor import Processor
class TestProcessor(unittest.TestCase):
- """Processor 类的单元测试"""
-
def setUp(self):
- """设置测试环境"""
self.processor = Processor()
self.sample_tokens = [
{
@@ -33,30 +25,26 @@ class TestProcessor(unittest.TestCase):
]
def test_init_without_rules(self):
- """测试无规则初始化"""
processor = Processor()
self.assertEqual(processor.rules, {})
def test_init_with_rules(self):
- """测试带规则初始化"""
rules = {"test_rule": "value"}
processor = Processor(rules)
self.assertEqual(processor.rules, rules)
def test_process_tokens(self):
- """测试处理 token 列表"""
result = self.processor.process_tokens(self.sample_tokens)
self.assertIsInstance(result, list)
self.assertEqual(len(result), len(self.sample_tokens))
- # 检查处理标记
+ # Check processing marks
for token in result:
if "timestamp" in token:
self.assertTrue(token.get("processed"))
def test_apply_rules(self):
- """测试应用规则到单个 token"""
token = self.sample_tokens[0]
result = self.processor.apply_rules(token)
@@ -65,7 +53,6 @@ class TestProcessor(unittest.TestCase):
self.assertTrue(result.get("processed"))
def test_generate_json_output(self):
- """测试生成 JSON 输出"""
output = self.processor.generate_json_output(self.sample_tokens)
self.assertIsInstance(output, str)
@@ -73,7 +60,6 @@ class TestProcessor(unittest.TestCase):
self.assertIn("speaker", output)
def test_generate_html_output(self):
- """测试生成 HTML 输出"""
output = self.processor.generate_html_output(self.sample_tokens)
self.assertIsInstance(output, str)
@@ -81,29 +67,25 @@ class TestProcessor(unittest.TestCase):
self.assertIn("</html>", output)
def test_generate_markdown_output(self):
- """测试生成 Markdown 输出"""
output = self.processor.generate_markdown_output(self.sample_tokens)
self.assertIsInstance(output, str)
self.assertIn("-", output)
def test_generate_output_json(self):
- """测试生成输出 - JSON 格式"""
output = self.processor.generate_output(self.sample_tokens, "json")
self.assertIsInstance(output, str)
def test_generate_output_html(self):
- """测试生成输出 - HTML 格式"""
+ output = self.processor.generate_output(self.sample_tokens, "html")
output = self.processor.generate_output(self.sample_tokens, "html")
self.assertIsInstance(output, str)
def test_generate_output_markdown(self):
- """测试生成输出 - Markdown 格式"""
output = self.processor.generate_output(self.sample_tokens, "markdown")
self.assertIsInstance(output, str)
def test_generate_output_unsupported_format(self):
- """测试生成输出 - 不支持的格式"""
with self.assertRaises(ValueError) as context:
self.processor.generate_output(self.sample_tokens, "pdf")