(app: App, monkeypatch: pytest.MonkeyPatch)
| 26 | |
| 27 | @pytest.mark.anyio |
| 28 | async def test_event_preprocessor(app: App, monkeypatch: pytest.MonkeyPatch): |
| 29 | with monkeypatch.context() as m: |
| 30 | m.setattr(message, "_event_preprocessors", set()) |
| 31 | |
| 32 | runned = False |
| 33 | |
| 34 | @event_preprocessor |
| 35 | async def test_preprocessor( |
| 36 | bot: Bot, |
| 37 | event: Event, |
| 38 | state: T_State, |
| 39 | sub: int = Depends(_dependency), |
| 40 | default: int = 1, |
| 41 | ): |
| 42 | nonlocal runned |
| 43 | runned = True |
| 44 | |
| 45 | assert test_preprocessor in { |
| 46 | dependent.call for dependent in message._event_preprocessors |
| 47 | } |
| 48 | |
| 49 | with app.provider.context({}): |
| 50 | matcher = on_message() |
| 51 | |
| 52 | async with app.test_matcher(matcher) as ctx: |
| 53 | bot = ctx.create_bot() |
| 54 | event = make_fake_event()() |
| 55 | ctx.receive_event(bot, event) |
| 56 | |
| 57 | assert runned, "event_preprocessor should runned" |
| 58 | |
| 59 | |
| 60 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected