mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-04 02:26:11 +08:00
🐛 fix config alias err
This commit is contained in:
parent
956b19d0c1
commit
a12a92fca4
@ -2,6 +2,7 @@ import nonebot
|
|||||||
from yarl import URL
|
from yarl import URL
|
||||||
from nonebot import get_plugin_config
|
from nonebot import get_plugin_config
|
||||||
from pydantic import Field, BaseModel
|
from pydantic import Field, BaseModel
|
||||||
|
from nonebot.compat import PYDANTIC_V2, ConfigDict
|
||||||
|
|
||||||
global_config = nonebot.get_driver().config
|
global_config = nonebot.get_driver().config
|
||||||
PlatformName = str
|
PlatformName = str
|
||||||
@ -9,6 +10,13 @@ ThemeName = str
|
|||||||
|
|
||||||
|
|
||||||
class PlugConfig(BaseModel):
|
class PlugConfig(BaseModel):
|
||||||
|
if PYDANTIC_V2:
|
||||||
|
model_config = ConfigDict(populate_by_name=True)
|
||||||
|
else:
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
allow_population_by_field_name = True
|
||||||
|
|
||||||
bison_config_path: str = ""
|
bison_config_path: str = ""
|
||||||
bison_use_pic: bool = Field(
|
bison_use_pic: bool = Field(
|
||||||
default=False,
|
default=False,
|
||||||
|
20
tests/test_plugin_config.py
Normal file
20
tests/test_plugin_config.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from nonebug.app import App
|
||||||
|
|
||||||
|
|
||||||
|
def test_parse_alias(app: App):
|
||||||
|
from nonebot.compat import PYDANTIC_V2
|
||||||
|
|
||||||
|
from nonebot_bison.plugin_config import PlugConfig
|
||||||
|
|
||||||
|
if PYDANTIC_V2:
|
||||||
|
cfg = PlugConfig.model_validate({"bison_theme_use_browser": True})
|
||||||
|
assert cfg.bison_use_browser
|
||||||
|
|
||||||
|
cfg = PlugConfig.model_validate({"bison_use_browser": True})
|
||||||
|
assert cfg.bison_use_browser
|
||||||
|
else:
|
||||||
|
cfg = PlugConfig.parse_obj({"bison_theme_use_browser": True})
|
||||||
|
assert cfg.bison_use_browser
|
||||||
|
|
||||||
|
cfg = PlugConfig.parse_obj({"bison_use_browser": True})
|
||||||
|
assert cfg.bison_use_browser
|
Loading…
x
Reference in New Issue
Block a user