Exemple #1
0
    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)
Exemple #2
0
    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)
Exemple #3
0
 def ubjdump(obj, fp, *args, **kwargs):
     return ubjdump(obj, fp, *args, **kwargs)
Exemple #4
0
 def ubjdumpb(obj, *args, **kwargs):
     out = BytesIO()
     ubjdump(obj, out, *args, **kwargs)
     return out.getvalue()
Exemple #5
0
 def test_fp(self):
     obj = {"a": 123, "b": 456}
     output = BytesIO()
     ubjdump({"a": 123, "b": 456}, output)
     self.assertEqual(ubjloadb(output.getvalue()), obj)