Ejemplo n.º 1
0
    def testSerializeThenDeserialize(self):
        obj = Xtruct2(i32_thing=1,
                      struct_thing=Xtruct(string_thing="foo"))

        s1 = serialize(obj)
        for i in range(10):
            self.assertEquals(s1, serialize(obj))
            objcopy = Xtruct2()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)

        obj = Xtruct(string_thing="bar")
        objcopy = Xtruct()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test booleans
        obj = Bools(im_true=True, im_false=False)
        objcopy = Bools()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test enums
        for num, name in Numberz._VALUES_TO_NAMES.items():
            obj = Bonk(message='enum Numberz value %d is string %s' % (num, name), type=num)
            objcopy = Bonk()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)
Ejemplo n.º 2
0
 def testNest(self):
     print('testNest')
     inner = Xtruct(string_thing="Zero",
                    byte_thing=1,
                    i32_thing=-3,
                    i64_thing=-5)
     x = Xtruct2(struct_thing=inner, byte_thing=0, i32_thing=0)
     y = self.client.testNest(x)
     self.assertEqual(y, x)
Ejemplo n.º 3
0
    def testSerializeThenDeserialize(self):
        obj = Xtruct2(i32_thing=1, struct_thing=Xtruct(string_thing="foo"))

        s1 = serialize(obj)
        for i in range(10):
            self.assertEquals(s1, serialize(obj))
            objcopy = Xtruct2()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)

        obj = Xtruct(string_thing="bar")
        objcopy = Xtruct()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test booleans
        obj = Bools(im_true=True, im_false=False)
        objcopy = Bools()
        deserialize(objcopy, serialize(obj))
        self.assertEquals(obj, objcopy)

        # test enums
        def _enumerate_enum(enum_class):
            if hasattr(enum_class, '_VALUES_TO_NAMES'):
                # old-style enums
                for num, name in enum_class._VALUES_TO_NAMES.items():
                    yield (num, name)
            else:
                # assume Python 3.4+ IntEnum-based
                from enum import IntEnum
                self.assertTrue((issubclass(enum_class, IntEnum)))
                for num in enum_class:
                    yield (num.value, num.name)

        for num, name in _enumerate_enum(Numberz):
            obj = Bonk(message='enum Numberz value %d is string %s' %
                       (num, name),
                       type=num)
            objcopy = Bonk()
            deserialize(objcopy, serialize(obj))
            self.assertEquals(obj, objcopy)