From b00fbdb23966d917f6e5dfe3f46b5814ce81b95c Mon Sep 17 00:00:00 2001 From: uy/sun Date: Tue, 16 Apr 2024 12:51:44 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=BB=98=E8=AE=A4=E4=BD=BF=E7=94=A8=20?= =?UTF-8?q?fake=20=E9=80=82=E9=85=8D=E5=99=A8=20(#212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + src/utils/plugin_test.py | 58 +++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a43ebac..f6dabd2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/lang/zh-CN/ ### Added - 使用 Pydantic 2.0 +- 默认使用 fake 适配器 ### Fixed diff --git a/src/utils/plugin_test.py b/src/utils/plugin_test.py index 22fffc8a..89effed6 100644 --- a/src/utils/plugin_test.py +++ b/src/utils/plugin_test.py @@ -30,18 +30,70 @@ RUNNER = """import json import os - -from nonebot import init, load_plugin, require, logger +from typing import override + +from nonebot import init, load_plugin, logger, require +from nonebot.drivers import ( + ASGIMixin, + HTTPClientMixin, + Request, + Response, + WebSocketClientMixin, +) +from nonebot.drivers import Driver as BaseDriver from pydantic import BaseModel +class Driver(BaseDriver, ASGIMixin, HTTPClientMixin, WebSocketClientMixin): + @property + @override + def type(self) -> str: + return "fake" + + @property + @override + def logger(self): + return logger + + @override + def run(self, *args, **kwargs): + super().run(*args, **kwargs) + + @property + @override + def server_app(self): + raise NotImplementedError + + @property + @override + def asgi(self): + raise NotImplementedError + + @override + def setup_http_server(self, setup): + raise NotImplementedError + + @override + def setup_websocket_server(self, setup): + raise NotImplementedError + + @override + async def request(self, setup: Request) -> Response: + raise NotImplementedError + + @override + async def websocket(self, setup: Request) -> Response: + raise NotImplementedError + + class SetEncoder(json.JSONEncoder): def default(self, obj): if isinstance(obj, set): return list(obj) return json.JSONEncoder.default(self, obj) -init() + +init(driver="runner") plugin = load_plugin("{}") if not plugin: