MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / test_run_preprocessor

Function test_run_preprocessor

tests/test_broadcast.py:205–238  ·  view source on GitHub ↗
(app: App, monkeypatch: pytest.MonkeyPatch)

Source from the content-addressed store, hash-verified

203
204@pytest.mark.anyio
205async def test_run_preprocessor(app: App, monkeypatch: pytest.MonkeyPatch):
206 with monkeypatch.context() as m:
207 m.setattr(message, "_run_preprocessors", set())
208
209 runned = False
210
211 @run_preprocessor
212 async def test_preprocessor(
213 bot: Bot,
214 event: Event,
215 state: T_State,
216 matcher: Matcher,
217 sub: int = Depends(_dependency),
218 default: int = 1,
219 ):
220 nonlocal runned
221 runned = True
222
223 await matcher.send("test")
224
225 assert test_preprocessor in {
226 dependent.call for dependent in message._run_preprocessors
227 }
228
229 with app.provider.context({}):
230 matcher = on_message()
231
232 async with app.test_matcher(matcher) as ctx:
233 bot = ctx.create_bot()
234 event = make_fake_event()()
235 ctx.receive_event(bot, event)
236 ctx.should_call_send(event, "test", True, bot=bot)
237
238 assert runned, "run_preprocessor should runned"
239
240
241@pytest.mark.anyio

Callers

nothing calls this directly

Calls 2

on_messageFunction · 0.90
make_fake_eventFunction · 0.90

Tested by

no test coverage detected