当前位置: 首页>>代码示例>>Python>>正文


Python message_factory.GetMessages方法代码示例

本文整理汇总了Python中google.protobuf.message_factory.GetMessages方法的典型用法代码示例。如果您正苦于以下问题:Python message_factory.GetMessages方法的具体用法?Python message_factory.GetMessages怎么用?Python message_factory.GetMessages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在google.protobuf.message_factory的用法示例。


在下文中一共展示了message_factory.GetMessages方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: testGetMessages

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testGetMessages(self):
    # performed twice because multiple calls with the same input must be allowed
    for _ in range(2):
      messages = message_factory.GetMessages([self.factory_test1_fd,
                                              self.factory_test2_fd])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message',
               'google.protobuf.python.internal.Factory1Message'],
             ).issubset(set(messages.keys())))
      self._ExerciseDynamicClass(
          messages['google.protobuf.python.internal.Factory2Message'])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message.one_more_field',
               'google.protobuf.python.internal.another_field'],
             ).issubset(
                 set(messages['google.protobuf.python.internal.Factory1Message']
                     ._extensions_by_name.keys())))
      factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
      msg1 = messages['google.protobuf.python.internal.Factory1Message']()
      ext1 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.Factory2Message.one_more_field']
      ext2 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.another_field']
      msg1.Extensions[ext1] = 'test1'
      msg1.Extensions[ext2] = 'test2'
      self.assertEqual('test1', msg1.Extensions[ext1])
      self.assertEqual('test2', msg1.Extensions[ext2]) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:29,代码来源:message_factory_test.py

示例2: testGetMessages

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testGetMessages(self):
    # performed twice because multiple calls with the same input must be allowed
    for _ in range(2):
      messages = message_factory.GetMessages([self.factory_test2_fd,
                                              self.factory_test1_fd])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message',
               'google.protobuf.python.internal.Factory1Message'],
             ).issubset(set(messages.keys())))
      self._ExerciseDynamicClass(
          messages['google.protobuf.python.internal.Factory2Message'])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message.one_more_field',
               'google.protobuf.python.internal.another_field'],
             ).issubset(
                set(messages['google.protobuf.python.internal.Factory1Message']
                     ._extensions_by_name.keys())))
      factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
      msg1 = messages['google.protobuf.python.internal.Factory1Message']()
      ext1 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.Factory2Message.one_more_field']
      ext2 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.another_field']
      msg1.Extensions[ext1] = 'test1'
      msg1.Extensions[ext2] = 'test2'
      self.assertEqual('test1', msg1.Extensions[ext1])
      self.assertEqual('test2', msg1.Extensions[ext2]) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:29,代码来源:message_factory_test.py

示例3: testGetMessages

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testGetMessages(self):
    # performed twice because multiple calls with the same input must be allowed
    for _ in range(2):
      messages = message_factory.GetMessages([self.factory_test2_fd,
                                              self.factory_test1_fd])
      self.assertContainsSubset(
          ['google.protobuf.python.internal.Factory2Message',
           'google.protobuf.python.internal.Factory1Message'],
          list(messages.keys()))
      self._ExerciseDynamicClass(
          messages['google.protobuf.python.internal.Factory2Message'])
      self.assertContainsSubset(
          ['google.protobuf.python.internal.Factory2Message.one_more_field',
           'google.protobuf.python.internal.another_field'],
          (list(messages['google.protobuf.python.internal.Factory1Message']
           ._extensions_by_name.keys())))
      factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
      msg1 = messages['google.protobuf.python.internal.Factory1Message']()
      ext1 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.Factory2Message.one_more_field']
      ext2 = factory_msg1._extensions_by_name[
          'google.protobuf.python.internal.another_field']
      msg1.Extensions[ext1] = 'test1'
      msg1.Extensions[ext2] = 'test2'
      self.assertEquals('test1', msg1.Extensions[ext1])
      self.assertEquals('test2', msg1.Extensions[ext2]) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:28,代码来源:message_factory_test.py

示例4: testGetMessages

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testGetMessages(self):
    # performed twice because multiple calls with the same input must be allowed
    for _ in range(2):
      messages = message_factory.GetMessages([self.factory_test1_fd,
                                              self.factory_test2_fd])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message',
               'google.protobuf.python.internal.Factory1Message'],
             ).issubset(set(messages.keys())))
      self._ExerciseDynamicClass(
          messages['google.protobuf.python.internal.Factory2Message'])
      factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
      self.assertTrue(set(
          ['google.protobuf.python.internal.Factory2Message.one_more_field',
           'google.protobuf.python.internal.another_field'],).issubset(set(
               ext.full_name
               for ext in factory_msg1.DESCRIPTOR.file.pool.FindAllExtensions(
                   factory_msg1.DESCRIPTOR))))
      msg1 = messages['google.protobuf.python.internal.Factory1Message']()
      ext1 = msg1.Extensions._FindExtensionByName(
          'google.protobuf.python.internal.Factory2Message.one_more_field')
      ext2 = msg1.Extensions._FindExtensionByName(
          'google.protobuf.python.internal.another_field')
      msg1.Extensions[ext1] = 'test1'
      msg1.Extensions[ext2] = 'test2'
      self.assertEqual('test1', msg1.Extensions[ext1])
      self.assertEqual('test2', msg1.Extensions[ext2]) 
开发者ID:apple,项目名称:coremltools,代码行数:29,代码来源:message_factory_test.py

示例5: testGetMessages

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testGetMessages(self):
    # performed twice because multiple calls with the same input must be allowed
    for _ in range(2):
      # GetMessage should work regardless of the order the FileDescriptorProto
      # are provided. In particular, the function should succeed when the files
      # are not in the topological order of dependencies.

      # Assuming factory_test2_fd depends on factory_test1_fd.
      self.assertIn(self.factory_test1_fd.name,
                    self.factory_test2_fd.dependency)
      # Get messages should work when a file comes before its dependencies:
      # factory_test2_fd comes before factory_test1_fd.
      messages = message_factory.GetMessages([self.factory_test2_fd,
                                              self.factory_test1_fd])
      self.assertTrue(
          set(['google.protobuf.python.internal.Factory2Message',
               'google.protobuf.python.internal.Factory1Message'],
             ).issubset(set(messages.keys())))
      self._ExerciseDynamicClass(
          messages['google.protobuf.python.internal.Factory2Message'])
      factory_msg1 = messages['google.protobuf.python.internal.Factory1Message']
      self.assertTrue(set(
          ['google.protobuf.python.internal.Factory2Message.one_more_field',
           'google.protobuf.python.internal.another_field'],).issubset(set(
               ext.full_name
               for ext in factory_msg1.DESCRIPTOR.file.pool.FindAllExtensions(
                   factory_msg1.DESCRIPTOR))))
      msg1 = messages['google.protobuf.python.internal.Factory1Message']()
      ext1 = msg1.Extensions._FindExtensionByName(
          'google.protobuf.python.internal.Factory2Message.one_more_field')
      ext2 = msg1.Extensions._FindExtensionByName(
          'google.protobuf.python.internal.another_field')
      msg1.Extensions[ext1] = 'test1'
      msg1.Extensions[ext2] = 'test2'
      self.assertEqual('test1', msg1.Extensions[ext1])
      self.assertEqual('test2', msg1.Extensions[ext2])
      self.assertEqual(None,
                       msg1.Extensions._FindExtensionByNumber(12321))
      if api_implementation.Type() == 'cpp':
        # TODO(jieluo): Fix len to return the correct value.
        # self.assertEqual(2, len(msg1.Extensions))
        self.assertEqual(len(msg1.Extensions), len(msg1.Extensions))
        self.assertRaises(TypeError,
                          msg1.Extensions._FindExtensionByName, 0)
        self.assertRaises(TypeError,
                          msg1.Extensions._FindExtensionByNumber, '')
      else:
        self.assertEqual(None,
                         msg1.Extensions._FindExtensionByName(0))
        self.assertEqual(None,
                         msg1.Extensions._FindExtensionByNumber('')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:53,代码来源:message_factory_test.py

示例6: testDuplicateExtensionNumber

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testDuplicateExtensionNumber(self):
    pool = descriptor_pool.DescriptorPool()
    factory = message_factory.MessageFactory(pool=pool)

    # Add Container message.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/container.proto'
    f.package = 'google.protobuf.python.internal'
    msg = f.message_type.add()
    msg.name = 'Container'
    rng = msg.extension_range.add()
    rng.start = 1
    rng.end = 10
    pool.Add(f)
    msgs = factory.GetMessages([f.name])
    self.assertIn('google.protobuf.python.internal.Container', msgs)

    # Extend container.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/extension.proto'
    f.package = 'google.protobuf.python.internal'
    f.dependency.append('google/protobuf/internal/container.proto')
    msg = f.message_type.add()
    msg.name = 'Extension'
    ext = msg.extension.add()
    ext.name = 'extension_field'
    ext.number = 2
    ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
    ext.type_name = 'Extension'
    ext.extendee = 'Container'
    pool.Add(f)
    msgs = factory.GetMessages([f.name])
    self.assertIn('google.protobuf.python.internal.Extension', msgs)

    # Add Duplicate extending the same field number.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/duplicate.proto'
    f.package = 'google.protobuf.python.internal'
    f.dependency.append('google/protobuf/internal/container.proto')
    msg = f.message_type.add()
    msg.name = 'Duplicate'
    ext = msg.extension.add()
    ext.name = 'extension_field'
    ext.number = 2
    ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
    ext.type_name = 'Duplicate'
    ext.extendee = 'Container'
    pool.Add(f)

    with self.assertRaises(Exception) as cm:
      factory.GetMessages([f.name])

    self.assertIn(str(cm.exception),
                  ['Extensions '
                   '"google.protobuf.python.internal.Duplicate.extension_field" and'
                   ' "google.protobuf.python.internal.Extension.extension_field"'
                   ' both try to extend message type'
                   ' "google.protobuf.python.internal.Container"'
                   ' with field number 2.',
                   'Double registration of Extensions']) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:62,代码来源:message_factory_test.py

示例7: testDuplicateExtensionNumber

# 需要导入模块: from google.protobuf import message_factory [as 别名]
# 或者: from google.protobuf.message_factory import GetMessages [as 别名]
def testDuplicateExtensionNumber(self):
    pool = descriptor_pool.DescriptorPool()
    factory = message_factory.MessageFactory(pool=pool)

    # Add Container message.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/container.proto'
    f.package = 'google.protobuf.python.internal'
    msg = f.message_type.add()
    msg.name = 'Container'
    rng = msg.extension_range.add()
    rng.start = 1
    rng.end = 10
    pool.Add(f)
    msgs = factory.GetMessages([f.name])
    self.assertIn('google.protobuf.python.internal.Container', msgs)

    # Extend container.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/extension.proto'
    f.package = 'google.protobuf.python.internal'
    f.dependency.append('google/protobuf/internal/container.proto')
    msg = f.message_type.add()
    msg.name = 'Extension'
    ext = msg.extension.add()
    ext.name = 'extension_field'
    ext.number = 2
    ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
    ext.type_name = 'Extension'
    ext.extendee = 'Container'
    pool.Add(f)
    msgs = factory.GetMessages([f.name])
    self.assertIn('google.protobuf.python.internal.Extension', msgs)

    # Add Duplicate extending the same field number.
    f = descriptor_pb2.FileDescriptorProto()
    f.name = 'google/protobuf/internal/duplicate.proto'
    f.package = 'google.protobuf.python.internal'
    f.dependency.append('google/protobuf/internal/container.proto')
    msg = f.message_type.add()
    msg.name = 'Duplicate'
    ext = msg.extension.add()
    ext.name = 'extension_field'
    ext.number = 2
    ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
    ext.type_name = 'Duplicate'
    ext.extendee = 'Container'
    pool.Add(f)

    with self.assertRaises(Exception) as cm:
      factory.GetMessages([f.name])

    self.assertIsInstance(cm.exception, (AssertionError, ValueError)) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:55,代码来源:message_factory_test.py


注:本文中的google.protobuf.message_factory.GetMessages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。