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

Function test_regex

tests/test_rule.py:491–515  ·  view source on GitHub ↗
(
    pattern: str,
    type: str,
    text: str | None,
    expected: bool,
    matched: Match[str] | None,
)

Source from the content-addressed store, hash-verified

489 ],
490)
491async def test_regex(
492 pattern: str,
493 type: str,
494 text: str | None,
495 expected: bool,
496 matched: Match[str] | None,
497):
498 test_regex = regex(pattern)
499 dependent = next(iter(test_regex.checkers))
500 checker = dependent.call
501
502 assert isinstance(checker, RegexRule)
503 assert checker.regex == pattern
504
505 message = text if text is None else FakeMessage(text)
506 event = make_fake_event(_type=type, _message=message)()
507 state = {}
508 assert await dependent(event=event, state=state) == expected
509 result: Match[str] | None = state.get(REGEX_MATCHED)
510 if matched is None:
511 assert result is None
512 else:
513 assert isinstance(result, Match)
514 assert result.group() == matched.group()
515 assert result.span() == matched.span()
516
517
518@pytest.mark.anyio

Callers

nothing calls this directly

Calls 4

regexFunction · 0.90
FakeMessageClass · 0.90
make_fake_eventFunction · 0.90
getMethod · 0.45

Tested by

no test coverage detected