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