def test_invalid_characters(): try: deserialize(b'i1@34$') except DeserializationError: pass else: assert False
def test_no_separator(): try: deserialize(b'i1i2s3') except DeserializationError: pass else: assert False
def test_too_long_integer(): try: a = deserialize(b'i' + b'6' * (10**6)) except DeserializationError: pass else: assert False
def test_invalid_starting_character(): try: i = deserialize(b'00000') except DeserializationError: pass else: print(i) assert False
def onGotPacket(self, packet, addr): if packet == '': return try: operands = deserialize(packet) except DeserializationError: print("Got malformed packet: " + repr(packet)) return (opcode, operands) = (operands[0], operands[1:]) key = self.tryFindKey(opcode) decoded_args = rep.decode_args_from_client(key, operands, self.player_for_addr(addr)) if self.verbose: log_recv_from_client(key, operands, decoded_args) self.tryCall(key, [addr] + list(decoded_args))
def test_bools(): lst = [False, True, False] assert lst == deserialize(serialize(lst))
def test_sanity_check(): deserialize(serialize([135, True, 'abc']))