(app: App)
| 22 | |
| 23 | @pytest.mark.anyio |
| 24 | async def test_permission(app: App): |
| 25 | async def falsy(): |
| 26 | return False |
| 27 | |
| 28 | async def truthy(): |
| 29 | return True |
| 30 | |
| 31 | async def skipped() -> bool: |
| 32 | raise SkippedException |
| 33 | |
| 34 | def _is_eq(a: Permission, b: Permission) -> bool: |
| 35 | return {d.call for d in a.checkers} == {d.call for d in b.checkers} |
| 36 | |
| 37 | assert _is_eq(Permission(truthy) | None, Permission(truthy)) |
| 38 | assert _is_eq(Permission(truthy) | falsy, Permission(truthy, falsy)) |
| 39 | assert _is_eq(Permission(truthy) | Permission(falsy), Permission(truthy, falsy)) |
| 40 | |
| 41 | assert _is_eq(None | Permission(truthy), Permission(truthy)) |
| 42 | assert _is_eq(truthy | Permission(falsy), Permission(truthy, falsy)) |
| 43 | |
| 44 | event = make_fake_event()() |
| 45 | |
| 46 | async with app.test_api() as ctx: |
| 47 | bot = ctx.create_bot() |
| 48 | assert await Permission(falsy)(bot, event) is False |
| 49 | assert await Permission(truthy)(bot, event) is True |
| 50 | assert await Permission(skipped)(bot, event) is False |
| 51 | assert await Permission(truthy, falsy)(bot, event) is True |
| 52 | assert await Permission(truthy, skipped)(bot, event) is True |
| 53 | |
| 54 | |
| 55 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected