예제 #1
0
    def testUnknownParseMismatchEnumValue(self):
        just_string = missing_enum_values_pb2.JustString()
        just_string.dummy = 'blah'

        missing = missing_enum_values_pb2.TestEnumValues()
        # The parse is invalid, storing the string proto into the set of
        # unknown fields.
        missing.ParseFromString(just_string.SerializeToString())

        # Fetching the enum field shouldn't crash, instead returning the
        # default value.
        self.assertEqual(missing.optional_nested_enum, 0)
예제 #2
0
  def setUp(self):
    self.descriptor = missing_enum_values_pb2.TestEnumValues.DESCRIPTOR

    self.message = missing_enum_values_pb2.TestEnumValues()
    self.message.optional_nested_enum = (
      missing_enum_values_pb2.TestEnumValues.ZERO)
    self.message.repeated_nested_enum.extend([
      missing_enum_values_pb2.TestEnumValues.ZERO,
      missing_enum_values_pb2.TestEnumValues.ONE,
      ])
    self.message.packed_nested_enum.extend([
      missing_enum_values_pb2.TestEnumValues.ZERO,
      missing_enum_values_pb2.TestEnumValues.ONE,
      ])
    self.message_data = self.message.SerializeToString()
    self.missing_message = missing_enum_values_pb2.TestMissingEnumValues()
    self.missing_message.ParseFromString(self.message_data)
    self.unknown_fields = self.missing_message._unknown_fields
예제 #3
0
    def setUp(self):
        self.descriptor = missing_enum_values_pb2.TestEnumValues.DESCRIPTOR

        self.message = missing_enum_values_pb2.TestEnumValues()
        # TestEnumValues.ZERO = 0, but does not exist in the other NestedEnum.
        self.message.optional_nested_enum = (
            missing_enum_values_pb2.TestEnumValues.ZERO)
        self.message.repeated_nested_enum.extend([
            missing_enum_values_pb2.TestEnumValues.ZERO,
            missing_enum_values_pb2.TestEnumValues.ONE,
        ])
        self.message.packed_nested_enum.extend([
            missing_enum_values_pb2.TestEnumValues.ZERO,
            missing_enum_values_pb2.TestEnumValues.ONE,
        ])
        self.message_data = self.message.SerializeToString()
        self.missing_message = missing_enum_values_pb2.TestMissingEnumValues()
        self.missing_message.ParseFromString(self.message_data)
예제 #4
0
 def testRoundTrip(self):
   new_message = missing_enum_values_pb2.TestEnumValues()
   new_message.ParseFromString(self.missing_message.SerializeToString())
   self.assertEqual(self.message, new_message)