Skip to content

Commit

Permalink
fix(plugin_test): 拆分成两个脚本
Browse files Browse the repository at this point in the history
否则加载驱动器时会重复加载插件
  • Loading branch information
he0119 committed Apr 16, 2024
1 parent 8a70d17 commit 50f014d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/utils/plugin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@
MODULE_NAME_PATTERN = re.compile(ISSUE_PATTERN.format("插件 import 包名"))
CONFIG_PATTERN = re.compile(r"### 插件配置项\s+```(?:\w+)?\s?([\s\S]*?)```")

RUNNER = """import json
import os
from nonebot import init, load_plugin, logger, require
FAKE_SCRIPT = """from nonebot import logger
from nonebot.drivers import (
ASGIMixin,
HTTPClientMixin,
Expand All @@ -41,7 +38,6 @@
WebSocketClientMixin,
)
from nonebot.drivers import Driver as BaseDriver
from pydantic import BaseModel
from typing_extensions import override
Expand Down Expand Up @@ -85,6 +81,13 @@ async def request(self, setup: Request) -> Response:
@override
async def websocket(self, setup: Request) -> Response:
raise NotImplementedError
"""

RUNNER_SCRIPT = """import json
import os
from nonebot import init, load_plugin, logger, require
from pydantic import BaseModel
class SetEncoder(json.JSONEncoder):
Expand All @@ -94,7 +97,7 @@ def default(self, obj):
return json.JSONEncoder.default(self, obj)
init(driver="runner")
init(driver="fake")
plugin = load_plugin("{}")
if not plugin:
Expand Down Expand Up @@ -295,9 +298,12 @@ async def run_poetry_project(self) -> None:
with open(self.path / ".env.prod", "w", encoding="utf8") as f:
f.write(self.config)

with open(self.path / "fake.py", "w", encoding="utf8") as f:
f.write(FAKE_SCRIPT)

with open(self.path / "runner.py", "w", encoding="utf8") as f:
f.write(
RUNNER.format(
RUNNER_SCRIPT.format(
self.module_name,
"\n".join([f"require('{i}')" for i in self._deps]),
)
Expand Down

0 comments on commit 50f014d

Please sign in to comment.