Beispiel #1
0
hm.bonks["something"] = [
    Bonk(**{"type": 1, "message": "Wait."}),
    Bonk(**{"type": 2, "message": "What?"}),
]
hm.bonks["poe"] = [
    Bonk(**{"type": 3, "message": "quoth"}),
    Bonk(**{"type": 4, "message": "the raven"}),
    Bonk(**{"type": 5, "message": "nevermore"}),
]

rs = RandomStuff()
rs.a = 1
rs.b = 2
rs.c = 3
rs.myintlist = range(20)
rs.maps = {1: Wrapper(**{"foo": Empty()}), 2: Wrapper(**{"foo": Empty()})}
rs.bigint = 124523452435
rs.triple = 3.14

# make sure this splits two buffers in a buffered protocol
rshuge = RandomStuff()
rshuge.myintlist = range(10000)

my_zero = Srv.Janky_result(**{"success": 5})


def check_write(o):
    trans_fast = TTransport.TMemoryBuffer()
    trans_slow = TTransport.TMemoryBuffer()
    prot_fast = TBinaryProtocol.TBinaryProtocolAccelerated(trans_fast)
    prot_slow = TBinaryProtocol.TBinaryProtocol(trans_slow)
Beispiel #2
0
 def test_struct(self):
     """Test that annotated struct can be serialized and deserialized"""
     x = Wrapper(foo=Empty())
     self.assertEqual(x.foo, Empty())
     x2 = self._roundtrip(x, Wrapper)
     self.assertEqual(x2.foo, Empty())
Beispiel #3
0
    def setUp(self):
        self.v1obj = VersioningTestV1(
            begin_in_both=12345,
            old_string='aaa',
            end_in_both=54321,
        )

        self.v2obj = VersioningTestV2(
            begin_in_both=12345,
            newint=1,
            newbyte=2,
            newshort=3,
            newlong=4,
            newdouble=5.0,
            newstruct=Bonk(message="Hello!", type=123),
            newlist=[7, 8, 9],
            newset=set([42, 1, 8]),
            newmap={
                1: 2,
                2: 3
            },
            newstring="Hola!",
            end_in_both=54321,
        )

        self.bools = Bools(im_true=True, im_false=False)
        self.bools_flipped = Bools(im_true=False, im_false=True)

        self.large_deltas = LargeDeltas(
            b1=self.bools,
            b10=self.bools_flipped,
            b100=self.bools,
            check_true=True,
            b1000=self.bools_flipped,
            check_false=False,
            vertwo2000=VersioningTestV2(
                newstruct=Bonk(message='World!', type=314)),
            a_set2500=set(['lazy', 'brown', 'cow']),
            vertwo3000=VersioningTestV2(newset=set([2, 3, 5, 7, 11])),
            big_numbers=[2**8, 2**16, 2**31 - 1, -(2**31 - 1)])

        self.compact_struct = CompactProtoTestStruct(
            a_byte=127,
            a_i16=32000,
            a_i32=1000000000,
            a_i64=0xffffffffff,
            a_double=5.6789,
            a_string="my string",
            true_field=True,
            false_field=False,
            empty_struct_field=Empty(),
            byte_list=[-127, -1, 0, 1, 127],
            i16_list=[-1, 0, 1, 0x7fff],
            i32_list=[-1, 0, 0xff, 0xffff, 0xffffff, 0x7fffffff],
            i64_list=[
                -1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff,
                0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff
            ],
            double_list=[0.1, 0.2, 0.3],
            string_list=["first", "second", "third"],
            boolean_list=[True, True, True, False, False, False],
            struct_list=[Empty(), Empty()],
            byte_set=set([-127, -1, 0, 1, 127]),
            i16_set=set([-1, 0, 1, 0x7fff]),
            i32_set=set([1, 2, 3]),
            i64_set=set([
                -1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff,
                0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff
            ]),
            double_set=set([0.1, 0.2, 0.3]),
            string_set=set(["first", "second", "third"]),
            boolean_set=set([True, False]),
            #struct_set=set([Empty()]), # unhashable instance
            byte_byte_map={1: 2},
            i16_byte_map={
                1: 1,
                -1: 1,
                0x7fff: 1
            },
            i32_byte_map={
                1: 1,
                -1: 1,
                0x7fffffff: 1
            },
            i64_byte_map={
                0: 1,
                1: 1,
                -1: 1,
                0x7fffffffffffffff: 1
            },
            double_byte_map={
                -1.1: 1,
                1.1: 1
            },
            string_byte_map={
                "first": 1,
                "second": 2,
                "third": 3,
                "": 0
            },
            boolean_byte_map={
                True: 1,
                False: 0
            },
            byte_i16_map={
                1: 1,
                2: -1,
                3: 0x7fff
            },
            byte_i32_map={
                1: 1,
                2: -1,
                3: 0x7fffffff
            },
            byte_i64_map={
                1: 1,
                2: -1,
                3: 0x7fffffffffffffff
            },
            byte_double_map={
                1: 0.1,
                2: -0.1,
                3: 1000000.1
            },
            byte_string_map={
                1: "",
                2: "blah",
                3: "loooooooooooooong string"
            },
            byte_boolean_map={
                1: True,
                2: False
            },
            #list_byte_map # unhashable
            #set_byte_map={set([1, 2, 3]) : 1, set([0, 1]) : 2, set([]) : 0}, # unhashable
            #map_byte_map # unhashable
            byte_map_map={
                0: {},
                1: {
                    1: 1
                },
                2: {
                    1: 1,
                    2: 2
                }
            },
            byte_set_map={
                0: set([]),
                1: set([1]),
                2: set([1, 2])
            },
            byte_list_map={
                0: [],
                1: [1],
                2: [1, 2]
            },
        )

        self.nested_lists_i32x2 = NestedListsI32x2([[1, 1, 2], [2, 7, 9],
                                                    [3, 5, 8]])

        self.nested_lists_i32x3 = NestedListsI32x3([[[2, 7, 9], [3, 5, 8]],
                                                    [[1, 1, 2], [1, 4, 9]]])

        self.nested_mixedx2 = NestedMixedx2(
            int_set_list=[
                set([1, 2, 3]),
                set([1, 4, 9]),
                set([1, 2, 3, 5, 8, 13, 21]),
                set([-1, 0, 1])
            ],
            # note, the sets below are sets of chars, since the strings are iterated
            map_int_strset={
                10: set('abc'),
                20: set('def'),
                30: set('GHI')
            },
            map_int_strset_list=[{
                10: set('abc'),
                20: set('def'),
                30: set('GHI')
            }, {
                100: set('lmn'),
                200: set('opq'),
                300: set('RST')
            }, {
                1000: set('uvw'),
                2000: set('wxy'),
                3000: set('XYZ')
            }])

        self.nested_lists_bonk = NestedListsBonk(
            [[[
                Bonk(message='inner A first', type=1),
                Bonk(message='inner A second', type=1)
            ],
              [
                  Bonk(message='inner B first', type=2),
                  Bonk(message='inner B second', type=2)
              ]]])

        self.list_bonks = ListBonks([
            Bonk(message='inner A', type=1),
            Bonk(message='inner B', type=2),
            Bonk(message='inner C', type=0)
        ])
Beispiel #4
0
 def test_empty_struct(self):
     """Test that annotated empty struct can be serialized and deserialized"""
     x = CompactProtoTestStruct(empty_struct_field=Empty())
     x2 = self._roundtrip(x, CompactProtoTestStruct())
     self.assertEqual(x2.empty_struct_field, Empty())
Beispiel #5
0
  def setUp(self):
      self.v1obj = VersioningTestV1(
          begin_in_both=12345,
          old_string='aaa',
          end_in_both=54321,
          )

      self.v2obj = VersioningTestV2(
          begin_in_both=12345,
          newint=1,
          newbyte=2,
          newshort=3,
          newlong=4,
          newdouble=5.0,
          newstruct=Bonk(message="Hello!", type=123),
          newlist=[7,8,9],
          newset=set([42,1,8]),
          newmap={1:2,2:3},
          newstring="Hola!",
          end_in_both=54321,
          )

      self.bools = Bools(im_true=True, im_false=False)
      self.bools_flipped = Bools(im_true=False, im_false=True)

      self.large_deltas = LargeDeltas (
          b1=self.bools,
          b10=self.bools_flipped,
          b100=self.bools,
          check_true=True,
          b1000=self.bools_flipped,
          check_false=False,
          vertwo2000=VersioningTestV2(newstruct=Bonk(message='World!', type=314)),
          a_set2500=set(['lazy', 'brown', 'cow']),
          vertwo3000=VersioningTestV2(newset=set([2, 3, 5, 7, 11])),
          big_numbers=[2**8, 2**16, 2**31-1, -(2**31-1)]
          )

      self.compact_struct = CompactProtoTestStruct(
          a_byte = 127,
          a_i16=32000,
          a_i32=1000000000,
          a_i64=0xffffffffff,
          a_double=5.6789,
          a_string="my string",
          true_field=True,
          false_field=False,
          empty_struct_field=Empty(),
          byte_list=[-127, -1, 0, 1, 127],
          i16_list=[-1, 0, 1, 0x7fff],
          i32_list= [-1, 0, 0xff, 0xffff, 0xffffff, 0x7fffffff],
          i64_list=[-1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff, 0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff],
          double_list=[0.1, 0.2, 0.3],
          string_list=["first", "second", "third"],
          boolean_list=[True, True, True, False, False, False],
          struct_list=[Empty(), Empty()],
          byte_set=set([-127, -1, 0, 1, 127]),
          i16_set=set([-1, 0, 1, 0x7fff]),
          i32_set=set([1, 2, 3]),
          i64_set=set([-1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff, 0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff]),
          double_set=set([0.1, 0.2, 0.3]),
          string_set=set(["first", "second", "third"]),
          boolean_set=set([True, False]),
          #struct_set=set([Empty()]), # unhashable instance
          byte_byte_map={1 : 2},
          i16_byte_map={1 : 1, -1 : 1, 0x7fff : 1},
          i32_byte_map={1 : 1, -1 : 1, 0x7fffffff : 1},
          i64_byte_map={0 : 1,  1 : 1, -1 : 1, 0x7fffffffffffffff : 1},
          double_byte_map={-1.1 : 1, 1.1 : 1},
          string_byte_map={"first" : 1, "second" : 2, "third" : 3, "" : 0},
          boolean_byte_map={True : 1, False: 0},
          byte_i16_map={1 : 1, 2 : -1, 3 : 0x7fff},
          byte_i32_map={1 : 1, 2 : -1, 3 : 0x7fffffff},
          byte_i64_map={1 : 1, 2 : -1, 3 : 0x7fffffffffffffff},
          byte_double_map={1 : 0.1, 2 : -0.1, 3 : 1000000.1},
          byte_string_map={1 : "", 2 : "blah", 3 : "loooooooooooooong string"},
          byte_boolean_map={1 : True, 2 : False},
          #list_byte_map # unhashable
          #set_byte_map={set([1, 2, 3]) : 1, set([0, 1]) : 2, set([]) : 0}, # unhashable
          #map_byte_map # unhashable
          byte_map_map={0 : {}, 1 : {1 : 1}, 2 : {1 : 1, 2 : 2}},
          byte_set_map={0 : set([]), 1 : set([1]), 2 : set([1, 2])},
          byte_list_map={0 : [], 1 : [1], 2 : [1, 2]},
          )