def testgoldenpackedmessage(self): golden_data = test_util.goldenfile("golden_packed_fields_message").read() golden_message = unittest_pb2.testpackedtypes() golden_message.parsefromstring(golden_data) all_set = unittest_pb2.testpackedtypes() test_util.setallpackedfields(all_set) self.assertequals(all_set, golden_message) self.assertequal(golden_data, all_set.serializetostring()) golden_copy = copy.deepcopy(golden_message) self.assertequal(golden_data, golden_copy.serializetostring())
def testnotanumberpacked(self): golden_data = "\xa2\x06\x04\x00\x00\xc0\x7f" "\xaa\x06\x08\x00\x00\x00\x00\x00\x00\xf8\x7f" golden_message = unittest_pb2.testpackedtypes() golden_message.parsefromstring(golden_data) self.asserttrue(isnan(golden_message.packed_float[0])) self.asserttrue(isnan(golden_message.packed_double[0])) serialized = golden_message.serializetostring() message = unittest_pb2.testpackedtypes() message.parsefromstring(serialized) self.asserttrue(isnan(message.packed_float[0])) self.asserttrue(isnan(message.packed_double[0]))
def testnegativeinfinitypacked(self): golden_data = "\xa2\x06\x04\x00\x00\x80\xff" "\xaa\x06\x08\x00\x00\x00\x00\x00\x00\xf0\xff" golden_message = unittest_pb2.testpackedtypes() golden_message.parsefromstring(golden_data) self.asserttrue(isneginf(golden_message.packed_float[0])) self.asserttrue(isneginf(golden_message.packed_double[0])) self.assertequal(golden_data, golden_message.serializetostring())