def test_invalid_fp_dump(self): with self.assertRaises(AttributeError): ubjdump(None, 1) class Dummy(object): write = 1 class Dummy2(object): @staticmethod def write(raw): raise ValueError('invalid - %s' % repr(raw)) with self.assertRaises(TypeError): ubjdump(b'', Dummy) with self.assertRaises(ValueError): ubjdump(b'', Dummy2)
def test_fp(self): obj = {"a": 123, "b": 456} output = BytesIO() ubjdump({"a": 123, "b": 456}, output) output.seek(0) self.assertEqual(ubjload(output), obj) # items which fit into extension decoder-internal read buffer (BUFFER_FP_SIZE in decoder.c) obj2 = ['fishy' * 64] * 10 output = BytesIO() ubjdump(obj, output) output.seek(0) self.assertEqual(ubjload(output), obj) # larger than extension read buffer obj2 = ['fishy' * 512] * 10 output.seek(0) ubjdump(obj2, output) output.seek(0) self.assertEqual(ubjload(output), obj2)
def ubjdump(obj, fp, *args, **kwargs): return ubjdump(obj, fp, *args, **kwargs)
def ubjdumpb(obj, *args, **kwargs): out = BytesIO() ubjdump(obj, out, *args, **kwargs) return out.getvalue()
def test_fp(self): obj = {"a": 123, "b": 456} output = BytesIO() ubjdump({"a": 123, "b": 456}, output) self.assertEqual(ubjloadb(output.getvalue()), obj)