aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tests/test_rule_extractor.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_rule_extractor.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_rule_extractor.py')
-rw-r--r--tests/test_rule_extractor.py17
1 files changed, 0 insertions, 17 deletions
diff --git a/tests/test_rule_extractor.py b/tests/test_rule_extractor.py
index 6c4d585..2c2815c 100644
--- a/tests/test_rule_extractor.py
+++ b/tests/test_rule_extractor.py
@@ -1,8 +1,3 @@
-#!/usr/bin/env python3
-"""
-RuleExtractor 模块单元测试
-"""
-
import unittest
import tempfile
import json5
@@ -11,11 +6,7 @@ from conventionalrp.extractors.rule_extractor import RuleExtractor
class TestRuleExtractor(unittest.TestCase):
- """RuleExtractor 类的单元测试"""
-
def setUp(self):
- """设置测试环境"""
- # 创建临时规则文件
self.temp_rules = tempfile.NamedTemporaryFile(
mode='w',
suffix='.json5',
@@ -30,23 +21,19 @@ class TestRuleExtractor(unittest.TestCase):
self.temp_rules.close()
def tearDown(self):
- """清理测试环境"""
Path(self.temp_rules.name).unlink(missing_ok=True)
def test_init_without_file(self):
- """测试不带配置文件的初始化"""
extractor = RuleExtractor()
self.assertEqual(extractor.rules, {})
self.assertIsNone(extractor.config_file)
def test_init_with_file(self):
- """测试带配置文件的初始化"""
extractor = RuleExtractor(self.temp_rules.name)
self.assertIsNotNone(extractor.rules)
self.assertIn("test_rule", extractor.rules)
def test_load_rules_from_file_success(self):
- """测试成功加载规则文件"""
extractor = RuleExtractor()
rules = extractor.load_rules_from_file(self.temp_rules.name)
@@ -55,13 +42,11 @@ class TestRuleExtractor(unittest.TestCase):
self.assertEqual(rules["test_rule"], "test_value")
def test_load_rules_from_file_not_found(self):
- """测试加载不存在的文件"""
extractor = RuleExtractor()
with self.assertRaises(FileNotFoundError):
extractor.load_rules_from_file("nonexistent.json5")
def test_load_rules_empty_file(self):
- """测试加载空文件"""
empty_file = tempfile.NamedTemporaryFile(
mode='w',
suffix='.json5',
@@ -79,7 +64,6 @@ class TestRuleExtractor(unittest.TestCase):
Path(empty_file.name).unlink(missing_ok=True)
def test_load_rules_method(self):
- """测试 load_rules 方法"""
extractor = RuleExtractor()
rules = extractor.load_rules(self.temp_rules.name)
@@ -87,7 +71,6 @@ class TestRuleExtractor(unittest.TestCase):
self.assertEqual(extractor.rules, rules)
def test_extract_method(self):
- """测试 extract 方法"""
extractor = RuleExtractor(self.temp_rules.name)
extracted = extractor.extract()