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

Function test_state

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

Source from the content-addressed store, hash-verified

362
363@pytest.mark.anyio
364async def test_state(app: App):
365 from plugins.param.param_state import (
366 command,
367 command_arg,
368 command_start,
369 command_whitespace,
370 endswith,
371 fullmatch,
372 keyword,
373 legacy_state,
374 not_legacy_state,
375 postpone_state,
376 raw_command,
377 regex_dict,
378 regex_group,
379 regex_matched,
380 regex_str,
381 shell_command_args,
382 shell_command_argv,
383 startswith,
384 state,
385 )
386
387 fake_message = FakeMessage("text")
388 fake_matched = re.match(r"\[cq:(?P<type>.*?),(?P<arg>.*?)\]", "[cq:test,arg=value]")
389 fake_state = {
390 PREFIX_KEY: {
391 CMD_KEY: ("cmd",),
392 RAW_CMD_KEY: "/cmd",
393 CMD_START_KEY: "/",
394 CMD_ARG_KEY: fake_message,
395 CMD_WHITESPACE_KEY: " ",
396 },
397 SHELL_ARGV: ["-h"],
398 SHELL_ARGS: {"help": True},
399 REGEX_MATCHED: fake_matched,
400 STARTSWITH_KEY: "startswith",
401 ENDSWITH_KEY: "endswith",
402 FULLMATCH_KEY: "fullmatch",
403 KEYWORD_KEY: "keyword",
404 }
405
406 async with app.test_dependent(state, allow_types=[StateParam]) as ctx:
407 ctx.pass_params(state=fake_state)
408 ctx.should_return(fake_state)
409
410 async with app.test_dependent(postpone_state, allow_types=[StateParam]) as ctx:
411 ctx.pass_params(state=fake_state)
412 ctx.should_return(fake_state)
413
414 async with app.test_dependent(legacy_state, allow_types=[StateParam]) as ctx:
415 ctx.pass_params(state=fake_state)
416 ctx.should_return(fake_state)
417
418 with pytest.raises(ValueError, match=UNKNOWN_PARAM):
419 app.test_dependent(not_legacy_state, allow_types=[StateParam])
420
421 async with app.test_dependent(

Callers

nothing calls this directly

Calls 1

FakeMessageClass · 0.90

Tested by

no test coverage detected