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


Python factory_test2_pb2.Factory2Message方法代码示例

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


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

示例1: _ExerciseDynamicClass

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [as 别名]
def _ExerciseDynamicClass(self, cls):
    msg = cls()
    msg.mandatory = 42
    msg.nested_factory_2_enum = 0
    msg.nested_factory_2_message.value = 'nested message value'
    msg.factory_1_message.factory_1_enum = 1
    msg.factory_1_message.nested_factory_1_enum = 0
    msg.factory_1_message.nested_factory_1_message.value = (
        'nested message value')
    msg.factory_1_message.scalar_value = 22
    msg.factory_1_message.list_value.extend(['one', 'two', 'three'])
    msg.factory_1_message.list_value.append('four')
    msg.factory_1_enum = 1
    msg.nested_factory_1_enum = 0
    msg.nested_factory_1_message.value = 'nested message value'
    msg.circular_message.mandatory = 1
    msg.circular_message.circular_message.mandatory = 2
    msg.circular_message.scalar_value = 'one deep'
    msg.scalar_value = 'zero deep'
    msg.list_value.extend(['four', 'three', 'two'])
    msg.list_value.append('one')
    msg.grouped.add()
    msg.grouped[0].part_1 = 'hello'
    msg.grouped[0].part_2 = 'world'
    msg.grouped.add(part_1='testing', part_2='123')
    msg.loop.loop.mandatory = 2
    msg.loop.loop.loop.loop.mandatory = 4
    serialized = msg.SerializeToString()
    converted = factory_test2_pb2.Factory2Message.FromString(serialized)
    reserialized = converted.SerializeToString()
    self.assertEqual(serialized, reserialized)
    result = cls.FromString(reserialized)
    self.assertEqual(msg, result) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:35,代码来源:message_factory_test.py

示例2: testGetPrototype

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [as 别名]
def testGetPrototype(self):
    db = descriptor_database.DescriptorDatabase()
    pool = descriptor_pool.DescriptorPool(db)
    db.Add(self.factory_test1_fd)
    db.Add(self.factory_test2_fd)
    factory = message_factory.MessageFactory()
    cls = factory.GetPrototype(pool.FindMessageTypeByName(
        'google.protobuf.python.internal.Factory2Message'))
    self.assertFalse(cls is factory_test2_pb2.Factory2Message)
    self._ExerciseDynamicClass(cls)
    cls2 = factory.GetPrototype(pool.FindMessageTypeByName(
        'google.protobuf.python.internal.Factory2Message'))
    self.assertTrue(cls is cls2) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:15,代码来源:message_factory_test.py

示例3: _ExerciseDynamicClass

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [as 别名]
def _ExerciseDynamicClass(self, cls):
    msg = cls()
    msg.mandatory = 42
    msg.nested_factory_2_enum = 0
    msg.nested_factory_2_message.value = 'nested message value'
    msg.factory_1_message.factory_1_enum = 1
    msg.factory_1_message.nested_factory_1_enum = 0
    msg.factory_1_message.nested_factory_1_message.value = (
        'nested message value')
    msg.factory_1_message.scalar_value = 22
    msg.factory_1_message.list_value.extend([u'one', u'two', u'three'])
    msg.factory_1_message.list_value.append(u'four')
    msg.factory_1_enum = 1
    msg.nested_factory_1_enum = 0
    msg.nested_factory_1_message.value = 'nested message value'
    msg.circular_message.mandatory = 1
    msg.circular_message.circular_message.mandatory = 2
    msg.circular_message.scalar_value = 'one deep'
    msg.scalar_value = 'zero deep'
    msg.list_value.extend([u'four', u'three', u'two'])
    msg.list_value.append(u'one')
    msg.grouped.add()
    msg.grouped[0].part_1 = 'hello'
    msg.grouped[0].part_2 = 'world'
    msg.grouped.add(part_1='testing', part_2='123')
    msg.loop.loop.mandatory = 2
    msg.loop.loop.loop.loop.mandatory = 4
    serialized = msg.SerializeToString()
    converted = factory_test2_pb2.Factory2Message.FromString(serialized)
    reserialized = converted.SerializeToString()
    self.assertEqual(serialized, reserialized)
    result = cls.FromString(reserialized)
    self.assertEqual(msg, result) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:35,代码来源:message_factory_test.py

示例4: testGetMessages

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [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

示例5: testGetMessages

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [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

示例6: _ExerciseDynamicClass

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [as 别名]
def _ExerciseDynamicClass(self, cls):
    msg = cls()
    msg.mandatory = 42
    msg.nested_factory_2_enum = 0
    msg.nested_factory_2_message.value = 'nested message value'
    msg.factory_1_message.factory_1_enum = 1
    msg.factory_1_message.nested_factory_1_enum = 0
    msg.factory_1_message.nested_factory_1_message.value = (
        'nested message value')
    msg.factory_1_message.scalar_value = 22
    msg.factory_1_message.list_value.extend(['one', 'two', 'three'])
    msg.factory_1_message.list_value.append('four')
    msg.factory_1_enum = 1
    msg.nested_factory_1_enum = 0
    msg.nested_factory_1_message.value = 'nested message value'
    msg.circular_message.mandatory = 1
    msg.circular_message.circular_message.mandatory = 2
    msg.circular_message.scalar_value = 'one deep'
    msg.scalar_value = 'zero deep'
    msg.list_value.extend(['four', 'three', 'two'])
    msg.list_value.append('one')
    msg.grouped.add()
    msg.grouped[0].part_1 = 'hello'
    msg.grouped[0].part_2 = 'world'
    msg.grouped.add(part_1='testing', part_2='123')
    msg.loop.loop.mandatory = 2
    msg.loop.loop.loop.loop.mandatory = 4
    serialized = msg.SerializeToString()
    converted = factory_test2_pb2.Factory2Message.FromString(serialized)
    reserialized = converted.SerializeToString()
    self.assertEquals(serialized, reserialized)
    result = cls.FromString(reserialized)
    self.assertEquals(msg, result) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:35,代码来源:message_factory_test.py

示例7: testGetPrototype

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [as 别名]
def testGetPrototype(self):
    db = descriptor_database.DescriptorDatabase()
    pool = descriptor_pool.DescriptorPool(db)
    db.Add(self.factory_test1_fd)
    db.Add(self.factory_test2_fd)
    factory = message_factory.MessageFactory()
    cls = factory.GetPrototype(pool.FindMessageTypeByName(
        'google.protobuf.python.internal.Factory2Message'))
    self.assertIsNot(cls, factory_test2_pb2.Factory2Message)
    self._ExerciseDynamicClass(cls)
    cls2 = factory.GetPrototype(pool.FindMessageTypeByName(
        'google.protobuf.python.internal.Factory2Message'))
    self.assertIs(cls, cls2) 
开发者ID:katharosada,项目名称:botchallenge,代码行数:15,代码来源:message_factory_test.py

示例8: testGetMessages

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [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

示例9: testGetMessages

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [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

示例10: testGetMessages

# 需要导入模块: from google.protobuf.internal import factory_test2_pb2 [as 别名]
# 或者: from google.protobuf.internal.factory_test2_pb2 import Factory2Message [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


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