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

Function test_matcher

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

Source from the content-addressed store, hash-verified

544
545@pytest.mark.anyio
546async def test_matcher(app: App):
547 from plugins.param.param_matcher import (
548 FooMatcher,
549 generic_matcher,
550 generic_matcher_none,
551 last_receive,
552 legacy_matcher,
553 matcher,
554 not_legacy_matcher,
555 not_matcher,
556 pause_prompt_result,
557 postpone_matcher,
558 receive,
559 receive_prompt_result,
560 sub_matcher,
561 union_matcher,
562 )
563
564 fake_matcher = Matcher()
565 foo_matcher = FooMatcher()
566
567 async with app.test_dependent(matcher, allow_types=[MatcherParam]) as ctx:
568 ctx.pass_params(matcher=fake_matcher)
569 ctx.should_return(fake_matcher)
570
571 async with app.test_dependent(postpone_matcher, allow_types=[MatcherParam]) as ctx:
572 ctx.pass_params(matcher=fake_matcher)
573 ctx.should_return(fake_matcher)
574
575 async with app.test_dependent(legacy_matcher, allow_types=[MatcherParam]) as ctx:
576 ctx.pass_params(matcher=fake_matcher)
577 ctx.should_return(fake_matcher)
578
579 with pytest.raises(ValueError, match=UNKNOWN_PARAM):
580 app.test_dependent(not_legacy_matcher, allow_types=[MatcherParam])
581
582 async with app.test_dependent(sub_matcher, allow_types=[MatcherParam]) as ctx:
583 ctx.pass_params(matcher=foo_matcher)
584 ctx.should_return(foo_matcher)
585
586 with pytest.raises((TypeMisMatch, BaseExceptionGroup)) as exc_info:
587 async with app.test_dependent(sub_matcher, allow_types=[MatcherParam]) as ctx:
588 ctx.pass_params(matcher=fake_matcher)
589
590 if isinstance(exc_info.value, BaseExceptionGroup):
591 assert exc_info.group_contains(TypeMisMatch)
592
593 async with app.test_dependent(union_matcher, allow_types=[MatcherParam]) as ctx:
594 ctx.pass_params(matcher=foo_matcher)
595 ctx.should_return(foo_matcher)
596
597 async with app.test_dependent(generic_matcher, allow_types=[MatcherParam]) as ctx:
598 ctx.pass_params(matcher=fake_matcher)
599 ctx.should_return(fake_matcher)
600
601 async with app.test_dependent(
602 generic_matcher_none, allow_types=[MatcherParam]
603 ) as ctx:

Callers

nothing calls this directly

Calls 9

set_receiveMethod · 0.95
set_targetMethod · 0.95
ensure_contextMethod · 0.95
rejectMethod · 0.95
pauseMethod · 0.95
MatcherClass · 0.90
FooMatcherClass · 0.90
make_fake_eventFunction · 0.90
formatMethod · 0.80

Tested by

no test coverage detected