Пример #1
0
    field_tag = encoder.TagBytes(field_descriptor.number, wire_type)
    result_dict = {}
    for tag_bytes, value in self.unknown_fields:
      if tag_bytes == field_tag:
        decoder = missing_enum_values_pb2.TestEnumValues._decoders_by_tag[
          tag_bytes][0]
        decoder(value, 0, len(value), self.message, result_dict)
    return result_dict[field_descriptor]

  def testUnknownEnumValue(self):
    self.assertFalse(self.missing_message.HasField('optional_nested_enum'))
    value = self.GetField('optional_nested_enum')
    self.assertEqual(self.message.optional_nested_enum, value)

  def testUnknownRepeatedEnumValue(self):
    value = self.GetField('repeated_nested_enum')
    self.assertEqual(self.message.repeated_nested_enum, value)

  def testUnknownPackedEnumValue(self):
    value = self.GetField('packed_nested_enum')
    self.assertEqual(self.message.packed_nested_enum, value)

  def testRoundTrip(self):
    new_message = missing_enum_values_pb2.TestEnumValues()
    new_message.ParseFromString(self.missing_message.SerializeToString())
    self.assertEqual(self.message, new_message)


if __name__ == '__main__':
  basetest.main()
Пример #2
0
def main(unused_argv):
  basetest.main()
Пример #3
0
def main(_):
  basetest.main()
def main(_):
  googletest.main()
Пример #5
0
    self.assertEqual(1, len(result.additional_properties))
    self.assertEqual(0, result.additional_properties[0].value.index)

  def testNestedFieldMapping(self):
    nested_msg = AdditionalPropertiesMessage()
    nested_msg.additional_properties = [
        AdditionalPropertiesMessage.AdditionalProperty(
            key='key_one', value='value_one'),
        AdditionalPropertiesMessage.AdditionalProperty(
            key='key_two', value='value_two'),
        ]
    msg = HasNestedMessage(nested=nested_msg)

    encoded_msg = encoding.MessageToJson(msg)
    self.assertEqual(
        {'nested': {'key_one': 'value_one', 'key_two': 'value_two'}},
        json.loads(encoded_msg))

    new_msg = encoding.JsonToMessage(type(msg), encoded_msg)
    self.assertEqual(
        set(('key_one', 'key_two')),
        set([x.key for x in new_msg.nested.additional_properties]))

    new_msg.nested.additional_properties.pop()
    self.assertEqual(1, len(new_msg.nested.additional_properties))
    self.assertEqual(2, len(msg.nested.additional_properties))


if __name__ == '__main__':
  googletest.main()