Only allow the given event type. If another event is passed, an AssertionError is raised.
(*event_types)
| 8 | |
| 9 | |
| 10 | def expect(*event_types): |
| 11 | """ |
| 12 | Only allow the given event type. |
| 13 | If another event is passed, an AssertionError is raised. |
| 14 | """ |
| 15 | |
| 16 | def decorator(f): |
| 17 | if __debug__ is True: |
| 18 | |
| 19 | @functools.wraps(f) |
| 20 | def _check_event_type(self, event: events.Event): |
| 21 | if isinstance(event, event_types): |
| 22 | return f(self, event) |
| 23 | else: |
| 24 | event_types_str = ( |
| 25 | "|".join(e.__name__ for e in event_types) or "no events" |
| 26 | ) |
| 27 | raise AssertionError( |
| 28 | f"Unexpected event type at {f.__qualname__}: " |
| 29 | f"Expected {event_types_str}, got {event}." |
| 30 | ) |
| 31 | |
| 32 | return _check_event_type |
| 33 | else: # pragma: no cover |
| 34 | return f |
| 35 | |
| 36 | return decorator |
| 37 | |
| 38 | |
| 39 | class ReceiveBuffer: |
no outgoing calls
searching dependent graphs…