David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
David Reiss | ea2cba8 | 2009-03-30 21:35:00 +0000 | [diff] [blame] | 3 | # |
| 4 | # Licensed to the Apache Software Foundation (ASF) under one |
| 5 | # or more contributor license agreements. See the NOTICE file |
| 6 | # distributed with this work for additional information |
| 7 | # regarding copyright ownership. The ASF licenses this file |
| 8 | # to you under the Apache License, Version 2.0 (the |
| 9 | # "License"); you may not use this file except in compliance |
| 10 | # with the License. You may obtain a copy of the License at |
| 11 | # |
| 12 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | # |
| 14 | # Unless required by applicable law or agreed to in writing, |
| 15 | # software distributed under the License is distributed on an |
| 16 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | # KIND, either express or implied. See the License for the |
| 18 | # specific language governing permissions and limitations |
| 19 | # under the License. |
| 20 | # |
| 21 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 22 | from ThriftTest.ttypes import * |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 23 | from DebugProtoTest.ttypes import CompactProtoTestStruct, Empty |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 24 | from thrift.transport import TTransport |
Roger Meier | ad8154a | 2012-12-18 21:02:16 +0100 | [diff] [blame] | 25 | from thrift.protocol import TBinaryProtocol, TCompactProtocol, TJSONProtocol |
David Reiss | 6acc269 | 2010-02-26 00:56:02 +0000 | [diff] [blame] | 26 | from thrift.TSerialization import serialize, deserialize |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 27 | import unittest |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 28 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 29 | |
| 30 | class AbstractTest(unittest.TestCase): |
| 31 | |
| 32 | def setUp(self): |
David Reiss | 46bb4ae | 2009-01-14 22:34:15 +0000 | [diff] [blame] | 33 | self.v1obj = VersioningTestV1( |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 34 | begin_in_both=12345, |
David Reiss | a528f54 | 2009-03-24 22:48:40 +0000 | [diff] [blame] | 35 | old_string='aaa', |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 36 | end_in_both=54321, |
David Reiss | 46bb4ae | 2009-01-14 22:34:15 +0000 | [diff] [blame] | 37 | ) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 38 | |
David Reiss | 46bb4ae | 2009-01-14 22:34:15 +0000 | [diff] [blame] | 39 | self.v2obj = VersioningTestV2( |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 40 | begin_in_both=12345, |
| 41 | newint=1, |
| 42 | newbyte=2, |
| 43 | newshort=3, |
| 44 | newlong=4, |
| 45 | newdouble=5.0, |
David Reiss | 46bb4ae | 2009-01-14 22:34:15 +0000 | [diff] [blame] | 46 | newstruct=Bonk(message="Hello!", type=123), |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 47 | newlist=[7,8,9], |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 48 | newset=set([42,1,8]), |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 49 | newmap={1:2,2:3}, |
| 50 | newstring="Hola!", |
| 51 | end_in_both=54321, |
David Reiss | 46bb4ae | 2009-01-14 22:34:15 +0000 | [diff] [blame] | 52 | ) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 53 | |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 54 | self.bools = Bools(im_true=True, im_false=False) |
| 55 | self.bools_flipped = Bools(im_true=False, im_false=True) |
| 56 | |
| 57 | self.large_deltas = LargeDeltas ( |
| 58 | b1=self.bools, |
| 59 | b10=self.bools_flipped, |
| 60 | b100=self.bools, |
| 61 | check_true=True, |
| 62 | b1000=self.bools_flipped, |
| 63 | check_false=False, |
| 64 | vertwo2000=VersioningTestV2(newstruct=Bonk(message='World!', type=314)), |
| 65 | a_set2500=set(['lazy', 'brown', 'cow']), |
| 66 | vertwo3000=VersioningTestV2(newset=set([2, 3, 5, 7, 11])), |
| 67 | big_numbers=[2**8, 2**16, 2**31-1, -(2**31-1)] |
| 68 | ) |
| 69 | |
| 70 | self.compact_struct = CompactProtoTestStruct( |
| 71 | a_byte = 127, |
| 72 | a_i16=32000, |
| 73 | a_i32=1000000000, |
| 74 | a_i64=0xffffffffff, |
| 75 | a_double=5.6789, |
| 76 | a_string="my string", |
| 77 | true_field=True, |
| 78 | false_field=False, |
| 79 | empty_struct_field=Empty(), |
| 80 | byte_list=[-127, -1, 0, 1, 127], |
| 81 | i16_list=[-1, 0, 1, 0x7fff], |
| 82 | i32_list= [-1, 0, 0xff, 0xffff, 0xffffff, 0x7fffffff], |
| 83 | i64_list=[-1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff, 0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff], |
| 84 | double_list=[0.1, 0.2, 0.3], |
| 85 | string_list=["first", "second", "third"], |
| 86 | boolean_list=[True, True, True, False, False, False], |
| 87 | struct_list=[Empty(), Empty()], |
| 88 | byte_set=set([-127, -1, 0, 1, 127]), |
| 89 | i16_set=set([-1, 0, 1, 0x7fff]), |
| 90 | i32_set=set([1, 2, 3]), |
| 91 | i64_set=set([-1, 0, 0xff, 0xffff, 0xffffff, 0xffffffff, 0xffffffffff, 0xffffffffffff, 0xffffffffffffff, 0x7fffffffffffffff]), |
| 92 | double_set=set([0.1, 0.2, 0.3]), |
| 93 | string_set=set(["first", "second", "third"]), |
| 94 | boolean_set=set([True, False]), |
| 95 | #struct_set=set([Empty()]), # unhashable instance |
| 96 | byte_byte_map={1 : 2}, |
| 97 | i16_byte_map={1 : 1, -1 : 1, 0x7fff : 1}, |
| 98 | i32_byte_map={1 : 1, -1 : 1, 0x7fffffff : 1}, |
| 99 | i64_byte_map={0 : 1, 1 : 1, -1 : 1, 0x7fffffffffffffff : 1}, |
| 100 | double_byte_map={-1.1 : 1, 1.1 : 1}, |
| 101 | string_byte_map={"first" : 1, "second" : 2, "third" : 3, "" : 0}, |
| 102 | boolean_byte_map={True : 1, False: 0}, |
| 103 | byte_i16_map={1 : 1, 2 : -1, 3 : 0x7fff}, |
| 104 | byte_i32_map={1 : 1, 2 : -1, 3 : 0x7fffffff}, |
| 105 | byte_i64_map={1 : 1, 2 : -1, 3 : 0x7fffffffffffffff}, |
| 106 | byte_double_map={1 : 0.1, 2 : -0.1, 3 : 1000000.1}, |
| 107 | byte_string_map={1 : "", 2 : "blah", 3 : "loooooooooooooong string"}, |
| 108 | byte_boolean_map={1 : True, 2 : False}, |
| 109 | #list_byte_map # unhashable |
| 110 | #set_byte_map={set([1, 2, 3]) : 1, set([0, 1]) : 2, set([]) : 0}, # unhashable |
| 111 | #map_byte_map # unhashable |
| 112 | byte_map_map={0 : {}, 1 : {1 : 1}, 2 : {1 : 1, 2 : 2}}, |
| 113 | byte_set_map={0 : set([]), 1 : set([1]), 2 : set([1, 2])}, |
| 114 | byte_list_map={0 : [], 1 : [1], 2 : [1, 2]}, |
| 115 | ) |
| 116 | |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 117 | self.nested_lists_i32x2 = NestedListsI32x2( |
| 118 | [ |
| 119 | [ 1, 1, 2 ], |
| 120 | [ 2, 7, 9 ], |
| 121 | [ 3, 5, 8 ] |
| 122 | ] |
| 123 | ) |
| 124 | |
| 125 | self.nested_lists_i32x3 = NestedListsI32x3( |
| 126 | [ |
| 127 | [ |
| 128 | [ 2, 7, 9 ], |
| 129 | [ 3, 5, 8 ] |
| 130 | ], |
| 131 | [ |
| 132 | [ 1, 1, 2 ], |
| 133 | [ 1, 4, 9 ] |
| 134 | ] |
| 135 | ] |
| 136 | ) |
| 137 | |
| 138 | self.nested_mixedx2 = NestedMixedx2( int_set_list=[ |
| 139 | set([1,2,3]), |
| 140 | set([1,4,9]), |
| 141 | set([1,2,3,5,8,13,21]), |
| 142 | set([-1, 0, 1]) |
| 143 | ], |
| 144 | # note, the sets below are sets of chars, since the strings are iterated |
| 145 | map_int_strset={ 10:set('abc'), 20:set('def'), 30:set('GHI') }, |
| 146 | map_int_strset_list=[ |
| 147 | { 10:set('abc'), 20:set('def'), 30:set('GHI') }, |
| 148 | { 100:set('lmn'), 200:set('opq'), 300:set('RST') }, |
| 149 | { 1000:set('uvw'), 2000:set('wxy'), 3000:set('XYZ') } |
| 150 | ] |
| 151 | ) |
| 152 | |
| 153 | self.nested_lists_bonk = NestedListsBonk( |
| 154 | [ |
| 155 | [ |
| 156 | [ |
| 157 | Bonk(message='inner A first', type=1), |
| 158 | Bonk(message='inner A second', type=1) |
| 159 | ], |
| 160 | [ |
| 161 | Bonk(message='inner B first', type=2), |
| 162 | Bonk(message='inner B second', type=2) |
| 163 | ] |
| 164 | ] |
| 165 | ] |
| 166 | ) |
| 167 | |
| 168 | self.list_bonks = ListBonks( |
| 169 | [ |
| 170 | Bonk(message='inner A', type=1), |
| 171 | Bonk(message='inner B', type=2), |
| 172 | Bonk(message='inner C', type=0) |
| 173 | ] |
| 174 | ) |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 175 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 176 | def _serialize(self, obj): |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 177 | trans = TTransport.TMemoryBuffer() |
| 178 | prot = self.protocol_factory.getProtocol(trans) |
| 179 | obj.write(prot) |
| 180 | return trans.getvalue() |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 181 | |
| 182 | def _deserialize(self, objtype, data): |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 183 | prot = self.protocol_factory.getProtocol(TTransport.TMemoryBuffer(data)) |
| 184 | ret = objtype() |
| 185 | ret.read(prot) |
| 186 | return ret |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 187 | |
| 188 | def testForwards(self): |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 189 | obj = self._deserialize(VersioningTestV2, self._serialize(self.v1obj)) |
| 190 | self.assertEquals(obj.begin_in_both, self.v1obj.begin_in_both) |
| 191 | self.assertEquals(obj.end_in_both, self.v1obj.end_in_both) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 192 | |
| 193 | def testBackwards(self): |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 194 | obj = self._deserialize(VersioningTestV1, self._serialize(self.v2obj)) |
| 195 | self.assertEquals(obj.begin_in_both, self.v2obj.begin_in_both) |
| 196 | self.assertEquals(obj.end_in_both, self.v2obj.end_in_both) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 197 | |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 198 | def testSerializeV1(self): |
| 199 | obj = self._deserialize(VersioningTestV1, self._serialize(self.v1obj)) |
| 200 | self.assertEquals(obj, self.v1obj) |
| 201 | |
| 202 | def testSerializeV2(self): |
| 203 | obj = self._deserialize(VersioningTestV2, self._serialize(self.v2obj)) |
| 204 | self.assertEquals(obj, self.v2obj) |
| 205 | |
| 206 | def testBools(self): |
| 207 | self.assertNotEquals(self.bools, self.bools_flipped) |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 208 | self.assertNotEquals(self.bools, self.v1obj) |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 209 | obj = self._deserialize(Bools, self._serialize(self.bools)) |
| 210 | self.assertEquals(obj, self.bools) |
| 211 | obj = self._deserialize(Bools, self._serialize(self.bools_flipped)) |
| 212 | self.assertEquals(obj, self.bools_flipped) |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 213 | rep = repr(self.bools) |
| 214 | self.assertTrue(len(rep) > 0) |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 215 | |
| 216 | def testLargeDeltas(self): |
| 217 | # test large field deltas (meaningful in CompactProto only) |
| 218 | obj = self._deserialize(LargeDeltas, self._serialize(self.large_deltas)) |
| 219 | self.assertEquals(obj, self.large_deltas) |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 220 | rep = repr(self.large_deltas) |
| 221 | self.assertTrue(len(rep) > 0) |
| 222 | |
| 223 | def testNestedListsI32x2(self): |
| 224 | obj = self._deserialize(NestedListsI32x2, self._serialize(self.nested_lists_i32x2)) |
| 225 | self.assertEquals(obj, self.nested_lists_i32x2) |
| 226 | rep = repr(self.nested_lists_i32x2) |
| 227 | self.assertTrue(len(rep) > 0) |
| 228 | |
| 229 | def testNestedListsI32x3(self): |
| 230 | obj = self._deserialize(NestedListsI32x3, self._serialize(self.nested_lists_i32x3)) |
| 231 | self.assertEquals(obj, self.nested_lists_i32x3) |
| 232 | rep = repr(self.nested_lists_i32x3) |
| 233 | self.assertTrue(len(rep) > 0) |
| 234 | |
| 235 | def testNestedMixedx2(self): |
| 236 | obj = self._deserialize(NestedMixedx2, self._serialize(self.nested_mixedx2)) |
| 237 | self.assertEquals(obj, self.nested_mixedx2) |
| 238 | rep = repr(self.nested_mixedx2) |
| 239 | self.assertTrue(len(rep) > 0) |
| 240 | |
| 241 | def testNestedListsBonk(self): |
| 242 | obj = self._deserialize(NestedListsBonk, self._serialize(self.nested_lists_bonk)) |
| 243 | self.assertEquals(obj, self.nested_lists_bonk) |
| 244 | rep = repr(self.nested_lists_bonk) |
| 245 | self.assertTrue(len(rep) > 0) |
| 246 | |
| 247 | def testListBonks(self): |
| 248 | obj = self._deserialize(ListBonks, self._serialize(self.list_bonks)) |
| 249 | self.assertEquals(obj, self.list_bonks) |
| 250 | rep = repr(self.list_bonks) |
| 251 | self.assertTrue(len(rep) > 0) |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 252 | |
| 253 | def testCompactStruct(self): |
| 254 | # test large field deltas (meaningful in CompactProto only) |
| 255 | obj = self._deserialize(CompactProtoTestStruct, self._serialize(self.compact_struct)) |
| 256 | self.assertEquals(obj, self.compact_struct) |
Roger Meier | f4eec7a | 2011-09-11 18:16:21 +0000 | [diff] [blame] | 257 | rep = repr(self.compact_struct) |
| 258 | self.assertTrue(len(rep) > 0) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 259 | |
Konrad Grochowski | d5f3be5 | 2014-10-08 15:32:21 +0200 | [diff] [blame] | 260 | def testIntegerLimits(self): |
| 261 | bad_values = [CompactProtoTestStruct(a_byte=128), CompactProtoTestStruct(a_byte=-129), |
| 262 | CompactProtoTestStruct(a_i16=32768), CompactProtoTestStruct(a_i16=-32769), |
| 263 | CompactProtoTestStruct(a_i32=2147483648), CompactProtoTestStruct(a_i32=-2147483649), |
| 264 | CompactProtoTestStruct(a_i64=9223372036854775808), CompactProtoTestStruct(a_i64=-9223372036854775809) |
| 265 | ] |
| 266 | |
| 267 | for value in bad_values: |
| 268 | self.assertRaises(Exception, self._serialize, value) |
| 269 | |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 270 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 271 | class NormalBinaryTest(AbstractTest): |
| 272 | protocol_factory = TBinaryProtocol.TBinaryProtocolFactory() |
| 273 | |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 274 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 275 | class AcceleratedBinaryTest(AbstractTest): |
| 276 | protocol_factory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory() |
| 277 | |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 278 | |
David Reiss | abafd79 | 2010-09-27 17:28:15 +0000 | [diff] [blame] | 279 | class CompactProtocolTest(AbstractTest): |
| 280 | protocol_factory = TCompactProtocol.TCompactProtocolFactory() |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 281 | |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 282 | |
Roger Meier | ad8154a | 2012-12-18 21:02:16 +0100 | [diff] [blame] | 283 | class JSONProtocolTest(AbstractTest): |
| 284 | protocol_factory = TJSONProtocol.TJSONProtocolFactory() |
| 285 | |
Nobuaki Sukegawa | cacce2f | 2015-11-08 23:43:55 +0900 | [diff] [blame] | 286 | |
David Reiss | 4c591c9 | 2009-01-31 21:39:25 +0000 | [diff] [blame] | 287 | class AcceleratedFramedTest(unittest.TestCase): |
| 288 | def testSplit(self): |
| 289 | """Test FramedTransport and BinaryProtocolAccelerated |
| 290 | |
| 291 | Tests that TBinaryProtocolAccelerated and TFramedTransport |
| 292 | play nicely together when a read spans a frame""" |
| 293 | |
| 294 | protocol_factory = TBinaryProtocol.TBinaryProtocolAcceleratedFactory() |
| 295 | bigstring = "".join(chr(byte) for byte in range(ord("a"), ord("z")+1)) |
| 296 | |
| 297 | databuf = TTransport.TMemoryBuffer() |
| 298 | prot = protocol_factory.getProtocol(databuf) |
| 299 | prot.writeI32(42) |
| 300 | prot.writeString(bigstring) |
| 301 | prot.writeI16(24) |
| 302 | data = databuf.getvalue() |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 303 | cutpoint = len(data) // 2 |
David Reiss | 4c591c9 | 2009-01-31 21:39:25 +0000 | [diff] [blame] | 304 | parts = [ data[:cutpoint], data[cutpoint:] ] |
| 305 | |
| 306 | framed_buffer = TTransport.TMemoryBuffer() |
| 307 | framed_writer = TTransport.TFramedTransport(framed_buffer) |
| 308 | for part in parts: |
| 309 | framed_writer.write(part) |
| 310 | framed_writer.flush() |
| 311 | self.assertEquals(len(framed_buffer.getvalue()), len(data) + 8) |
| 312 | |
| 313 | # Recreate framed_buffer so we can read from it. |
| 314 | framed_buffer = TTransport.TMemoryBuffer(framed_buffer.getvalue()) |
| 315 | framed_reader = TTransport.TFramedTransport(framed_buffer) |
| 316 | prot = protocol_factory.getProtocol(framed_reader) |
| 317 | self.assertEqual(prot.readI32(), 42) |
| 318 | self.assertEqual(prot.readString(), bigstring) |
| 319 | self.assertEqual(prot.readI16(), 24) |
| 320 | |
David Reiss | 6acc269 | 2010-02-26 00:56:02 +0000 | [diff] [blame] | 321 | class SerializersTest(unittest.TestCase): |
| 322 | |
| 323 | def testSerializeThenDeserialize(self): |
| 324 | obj = Xtruct2(i32_thing=1, |
| 325 | struct_thing=Xtruct(string_thing="foo")) |
| 326 | |
| 327 | s1 = serialize(obj) |
| 328 | for i in range(10): |
| 329 | self.assertEquals(s1, serialize(obj)) |
| 330 | objcopy = Xtruct2() |
| 331 | deserialize(objcopy, serialize(obj)) |
| 332 | self.assertEquals(obj, objcopy) |
| 333 | |
| 334 | obj = Xtruct(string_thing="bar") |
| 335 | objcopy = Xtruct() |
| 336 | deserialize(objcopy, serialize(obj)) |
| 337 | self.assertEquals(obj, objcopy) |
David Reiss | 4c591c9 | 2009-01-31 21:39:25 +0000 | [diff] [blame] | 338 | |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 339 | # test booleans |
| 340 | obj = Bools(im_true=True, im_false=False) |
| 341 | objcopy = Bools() |
| 342 | deserialize(objcopy, serialize(obj)) |
| 343 | self.assertEquals(obj, objcopy) |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 344 | |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 345 | # test enums |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 346 | for num, name in Numberz._VALUES_TO_NAMES.items(): |
Bryan Duxbury | df4cffd | 2011-03-15 17:16:09 +0000 | [diff] [blame] | 347 | obj = Bonk(message='enum Numberz value %d is string %s' % (num, name), type=num) |
| 348 | objcopy = Bonk() |
| 349 | deserialize(objcopy, serialize(obj)) |
| 350 | self.assertEquals(obj, objcopy) |
Nobuaki Sukegawa | 760511f | 2015-11-06 21:24:16 +0900 | [diff] [blame] | 351 | |
David Reiss | 4c591c9 | 2009-01-31 21:39:25 +0000 | [diff] [blame] | 352 | |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 353 | def suite(): |
| 354 | suite = unittest.TestSuite() |
| 355 | loader = unittest.TestLoader() |
| 356 | |
| 357 | suite.addTest(loader.loadTestsFromTestCase(NormalBinaryTest)) |
| 358 | suite.addTest(loader.loadTestsFromTestCase(AcceleratedBinaryTest)) |
David Reiss | abafd79 | 2010-09-27 17:28:15 +0000 | [diff] [blame] | 359 | suite.addTest(loader.loadTestsFromTestCase(CompactProtocolTest)) |
Roger Meier | ad8154a | 2012-12-18 21:02:16 +0100 | [diff] [blame] | 360 | suite.addTest(loader.loadTestsFromTestCase(JSONProtocolTest)) |
David Reiss | 4c591c9 | 2009-01-31 21:39:25 +0000 | [diff] [blame] | 361 | suite.addTest(loader.loadTestsFromTestCase(AcceleratedFramedTest)) |
David Reiss | 6acc269 | 2010-02-26 00:56:02 +0000 | [diff] [blame] | 362 | suite.addTest(loader.loadTestsFromTestCase(SerializersTest)) |
David Reiss | 9ff3b9d | 2008-02-15 01:10:23 +0000 | [diff] [blame] | 363 | return suite |
| 364 | |
| 365 | if __name__ == "__main__": |
| 366 | unittest.main(defaultTest="suite", testRunner=unittest.TextTestRunner(verbosity=2)) |