mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-26 07:41:20 +00:00
✅ add more depend test case
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from dataclasses import dataclass
|
||||
|
||||
from nonebot import on_message
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.params import Depends
|
||||
|
||||
test_depends = on_message()
|
||||
@ -17,6 +18,20 @@ def parameterless():
|
||||
runned.append(1)
|
||||
|
||||
|
||||
def gen_sync():
|
||||
yield 1
|
||||
|
||||
|
||||
async def gen_async():
|
||||
yield 2
|
||||
|
||||
|
||||
@dataclass
|
||||
class ClassDependency:
|
||||
x: int = Depends(gen_sync)
|
||||
y: int = Depends(gen_async)
|
||||
|
||||
|
||||
# test parameterless
|
||||
@test_depends.handle(parameterless=[Depends(parameterless)])
|
||||
async def depends(x: int = Depends(dependency)):
|
||||
@ -28,3 +43,7 @@ async def depends(x: int = Depends(dependency)):
|
||||
async def depends_cache(y: int = Depends(dependency, use_cache=True)):
|
||||
# test cache
|
||||
return y
|
||||
|
||||
|
||||
async def class_depend(c: ClassDependency = Depends()):
|
||||
return c
|
||||
|
Reference in New Issue
Block a user