def _test_get_buffer(self, pack_func, **kwargs): packer = msgpack.Packer(autoreset=False, use_bin_type=True) packer.pack([1, 2]) strm = BytesIO() strm.write(packer.getbuffer()) written = strm.getvalue() expected = pack_func([1, 2], use_bin_type=True) self.assertEqual(expected, written)
def test_Unpacker(self): data = os.urandom(1024) packer = msgpack.Packer() unpacker = salt.utils.msgpack.Unpacker(None) packed = packer.pack(data) # Sanity Check self.assertTrue(packed) self.assertNotEqual(data, packed) # Reverse the packing and the result should be equivalent to the original data unpacker.feed(packed) unpacked = msgpack.unpackb(packed) self.assertEqual(data, unpacked)