Beispiel #1
0
 def setUp(self):
   self.descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
   self.all_fields = unittest_pb2.TestAllTypes()
   test_util.SetAllFields(self.all_fields)
   self.all_fields_data = self.all_fields.SerializeToString()
   self.empty_message = unittest_pb2.TestEmptyMessage()
   self.empty_message.ParseFromString(self.all_fields_data)
Beispiel #2
0
  def testEquals(self):
    message = unittest_pb2.TestEmptyMessage()
    message.ParseFromString(self.all_fields_data)
    self.assertEqual(self.empty_message, message)

    self.all_fields.ClearField('optional_string')
    message.ParseFromString(self.all_fields.SerializeToString())
    self.assertNotEqual(self.empty_message, message)
Beispiel #3
0
  def testMergeFrom(self):
    message = unittest_pb2.TestAllTypes()
    message.optional_int32 = 1
    message.optional_uint32 = 2
    source = unittest_pb2.TestEmptyMessage()
    source.ParseFromString(message.SerializeToString())

    message.ClearField('optional_int32')
    message.optional_int64 = 3
    message.optional_uint32 = 4
    destination = unittest_pb2.TestEmptyMessage()
    destination.ParseFromString(message.SerializeToString())

    destination.MergeFrom(source)
    # Check that the fields where correctly merged, even stored in the unknown
    # fields set.
    message.ParseFromString(destination.SerializeToString())
    self.assertEqual(message.optional_int32, 1)
    self.assertEqual(message.optional_uint32, 2)
    self.assertEqual(message.optional_int64, 3)
Beispiel #4
0
 def testCopyFrom(self):
   message = unittest_pb2.TestEmptyMessage()
   message.CopyFrom(self.empty_message)
   self.assertEqual(message.SerializeToString(), self.all_fields_data)