def cmp_msg(msg: Message, expected: Message) -> Optional[str]: """Return None if every field in expected matches a field in msg. Otherwise return a complaint""" if msg.messagetype != expected.messagetype: return "Expected {}, got {}".format(expected.messagetype, msg.messagetype) obj = msg.to_py() expected_obj = expected.to_py() return cmp_obj(obj, expected_obj, expected.messagetype.name)
def msg_to_stash(runner: 'Runner', event: Event, msg: Message) -> None: """ExpectMsg and Msg save every field to the stash, in order""" fields = msg.to_py() stash = runner.get_stash(event, type(event).__name__, []) stash.append((msg.messagetype.name, fields)) runner.add_stash(type(event).__name__, stash)