MCPcopy
hub / github.com/nonebot/nonebot2 / test_depend

Function test_depend

tests/test_param.py:50–162  ·  view source on GitHub ↗
(app: App)

Source from the content-addressed store, hash-verified

48 reason="CPython Bug, see python/cpython#137317, python/cpython#137862",
49)
50async def test_depend(app: App):
51 from plugins.param.param_depend import (
52 ClassDependency,
53 annotated_class_depend,
54 annotated_depend,
55 annotated_multi_depend,
56 annotated_prior_depend,
57 cache_exception_func1,
58 cache_exception_func2,
59 class_depend,
60 depends,
61 runned,
62 sub_type_mismatch,
63 test_depends,
64 validate,
65 validate_fail,
66 validate_field,
67 validate_field_fail,
68 )
69
70 async with app.test_dependent(depends, allow_types=[DependParam]) as ctx:
71 ctx.should_return(1)
72
73 assert len(runned) == 1
74 assert runned[0] == 1
75
76 runned.clear()
77
78 async with app.test_matcher(test_depends) as ctx:
79 bot = ctx.create_bot()
80 event_next = make_fake_event()()
81 ctx.receive_event(bot, event_next)
82
83 assert runned == [1, 1]
84
85 runned.clear()
86
87 async with app.test_dependent(class_depend, allow_types=[DependParam]) as ctx:
88 ctx.should_return(ClassDependency(x=1, y=2))
89
90 async with app.test_dependent(annotated_depend, allow_types=[DependParam]) as ctx:
91 ctx.should_return(1)
92
93 async with app.test_dependent(
94 annotated_prior_depend, allow_types=[DependParam]
95 ) as ctx:
96 ctx.should_return(1)
97
98 async with app.test_dependent(
99 annotated_multi_depend, allow_types=[DependParam]
100 ) as ctx:
101 ctx.should_return(1)
102
103 assert runned == [1, 1, 1]
104
105 runned.clear()
106
107 async with app.test_dependent(

Callers

nothing calls this directly

Calls 3

make_fake_eventFunction · 0.90
ClassDependencyClass · 0.90
clearMethod · 0.45

Tested by

no test coverage detected