diff options
| author | 2023-12-15 18:40:31 +0800 | |
|---|---|---|
| committer | 2023-12-15 18:40:31 +0800 | |
| commit | 02b019a663aff80cd9e51ec91dccab81a15a14d8 (patch) | |
| tree | f815694823f993971fe2a609825e8354af3ac94a /tests/MyRule/core.py | |
| parent | 57e09bc268cde8f73d1fc828f0ae80e16c9337d4 (diff) | |
| download | infini-02b019a663aff80cd9e51ec91dccab81a15a14d8.tar.gz infini-02b019a663aff80cd9e51ec91dccab81a15a14d8.zip | |
chore(tests): test generate `RulePackage`
Diffstat (limited to 'tests/MyRule/core.py')
| -rw-r--r-- | tests/MyRule/core.py | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/tests/MyRule/core.py b/tests/MyRule/core.py deleted file mode 100644 index acebe644..00000000 --- a/tests/MyRule/core.py +++ /dev/null @@ -1,43 +0,0 @@ -import os -import importlib -from typing import List -from pydantic import BaseModel -import asyncio - -class Rule(BaseModel): - name: str - config_name: str - - async def success(self): - # 处理成功事件的逻辑 - pass - - async def fail(self): - # 处理失败事件的逻辑 - pass - -async def load_rules_from_folder(folder_path: str) -> List[Rule]: - rules = [] - for file_name in os.listdir(folder_path): - if file_name.endswith(".py"): - module_name = file_name[:-3] - module = importlib.import_module(module_name) - for name, obj in module.__dict__.items(): - if isinstance(obj, type) and issubclass(obj, Rule) and obj != Rule: - rules.append(obj()) - return rules - -async def process_event(rules: List[Rule], event: str): - tasks = [] - for rule in rules: - if hasattr(rule, event): - task = getattr(rule, event)() - tasks.append(task) - await asyncio.gather(*tasks) - -async def main(): - folder_path = "tests/MyRule/Rule" - rules = await load_rules_from_folder(folder_path) - await process_event(rules, "success") - -asyncio.run(main()) |
