(
pattern: str,
type: str,
text: str | None,
expected: bool,
matched: Match[str] | None,
)
| 489 | ], |
| 490 | ) |
| 491 | async 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 |
nothing calls this directly
no test coverage detected