def test_unpack_exceptions(self): for (name, data, exception) in unpack_exception_test_vectors: print("\tTesting %s" % name) try: umsgpack_s.unpackb(data) except Exception as e: self.assertTrue(isinstance(e, exception))
def _handle_msg(self, msg_as_bytes): if DEBUG > 3: sys.stderr.write('%s handling message: %s\n' % (self, binascii.b2a_hex(msg_as_bytes))) initial_time = time.time() decoded = umsgpack_s.unpackb(msg_as_bytes) self.time_to_unpack_last_message = time.time() - initial_time self._handle_decoded(decoded)
def test_unpack_composite(self): for (name, obj, data) in composite_test_vectors: obj_repr = repr(obj) print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "...")) self.assertEqual(umsgpack_s.unpackb(data), obj)
def test_pack_composite(self): for (name, obj, data) in composite_test_vectors: obj_repr = repr(obj) print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "...")) packed = umsgpack_s.packb(obj) self.assertEqual(packed, data) self.assertEqual(umsgpack_s.unpackb(packed), obj)
def test_pack_single(self): for (name, obj, data) in single_test_vectors: obj_repr = repr(obj) print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "...")) packed = umsgpack_s.packb(obj) self.assertEqual(packed, data) self.assertEqual(umsgpack_s.unpackb(packed), obj)
def test_unpack_single(self): for (name, obj, data) in single_test_vectors: obj_repr = repr(obj) print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "...")) unpacked = umsgpack_s.unpackb(data) # In Python2, we have both int and long integer types, but which # one we end up with depends on the architecture (32-bit/64-bit) if sys.version_info[0] == 2: # Allow both {int,long} -> unpackb -> {int,long} if isinstance(obj, int) or isinstance(obj, long): self.assertTrue(isinstance(unpacked, int) or isinstance(unpacked, long)) else: self.assertTrue(isinstance(unpacked, type(obj))) # In Python3, we only have the int integer type else: self.assertTrue(isinstance(unpacked, type(obj))) self.assertEqual(unpacked, obj)
def test_unpack_single(self): for (name, obj, data) in single_test_vectors: obj_repr = repr(obj) print("\tTesting %s: object %s" % (name, obj_repr if len(obj_repr) < 24 else obj_repr[0:24] + "...")) unpacked = umsgpack_s.unpackb(data) # In Python2, we have both int and long integer types, but which # one we end up with depends on the architecture (32-bit/64-bit) if sys.version_info[0] == 2: # Allow both {int,long} -> unpackb -> {int,long} if isinstance(obj, int) or isinstance(obj, long): self.assertTrue( isinstance(unpacked, int) or isinstance(unpacked, long)) else: self.assertTrue(isinstance(unpacked, type(obj))) # In Python3, we only have the int integer type else: self.assertTrue(isinstance(unpacked, type(obj))) self.assertEqual(unpacked, obj)