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


Python message.ClearField方法代码示例

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


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

示例1: testOneofWhichOneof

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testOneofWhichOneof(self, message_module):
    m = message_module.TestAllTypes()
    self.assertIs(None, m.WhichOneof('oneof_field'))
    if message_module is unittest_pb2:
      self.assertFalse(m.HasField('oneof_field'))

    m.oneof_uint32 = 11
    self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field'))
    if message_module is unittest_pb2:
      self.assertTrue(m.HasField('oneof_field'))

    m.oneof_bytes = b'bb'
    self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field'))

    m.ClearField('oneof_bytes')
    self.assertIs(None, m.WhichOneof('oneof_field'))
    if message_module is unittest_pb2:
      self.assertFalse(m.HasField('oneof_field')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:20,代码来源:message_test.py

示例2: testMapIterInvalidatedByClearField

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMapIterInvalidatedByClearField(self):
    # Map iterator is invalidated when field is cleared.
    # But this case does need to not crash the interpreter.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()

    it = iter(msg.map_int32_int32)

    msg.ClearField('map_int32_int32')
    with self.assertRaises(RuntimeError):
      for _ in it:
        pass

    it = iter(msg.map_int32_foreign_message)
    msg.ClearField('map_int32_foreign_message')
    with self.assertRaises(RuntimeError):
      for _ in it:
        pass 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:message_test.py

示例3: testOneofClearField

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testOneofClearField(self, message_module):
    m = message_module.TestAllTypes()
    m.oneof_uint32 = 11
    m.ClearField('oneof_field')
    if message_module is unittest_pb2:
      self.assertFalse(m.HasField('oneof_field'))
    self.assertFalse(m.HasField('oneof_uint32'))
    self.assertIs(None, m.WhichOneof('oneof_field')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:message_test.py

示例4: testOneofClearSetField

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testOneofClearSetField(self, message_module):
    m = message_module.TestAllTypes()
    m.oneof_uint32 = 11
    m.ClearField('oneof_uint32')
    if message_module is unittest_pb2:
      self.assertFalse(m.HasField('oneof_field'))
    self.assertFalse(m.HasField('oneof_uint32'))
    self.assertIs(None, m.WhichOneof('oneof_field')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:10,代码来源:message_test.py

示例5: testOneofClearUnsetField

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testOneofClearUnsetField(self, message_module):
    m = message_module.TestAllTypes()
    m.oneof_uint32 = 11
    self.ensureNestedMessageExists(m, 'oneof_nested_message')
    m.ClearField('oneof_nested_message')
    self.assertEqual(11, m.oneof_uint32)
    if message_module is unittest_pb2:
      self.assertTrue(m.HasField('oneof_field'))
    self.assertTrue(m.HasField('oneof_uint32'))
    self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:12,代码来源:message_test.py

示例6: testMapValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMapValidAfterFieldCleared(self):
    # Map needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()
    int32_map = msg.map_int32_int32

    int32_map[2] = 4
    int32_map[3] = 6
    int32_map[4] = 8

    msg.ClearField('map_int32_int32')
    self.assertEqual(b'', msg.SerializeToString())
    matching_dict = {2: 4, 3: 6, 4: 8}
    self.assertMapIterEquals(list(int32_map.items()), matching_dict) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:17,代码来源:message_test.py

示例7: testMessageMapValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMessageMapValidAfterFieldCleared(self):
    # Map needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()
    int32_foreign_message = msg.map_int32_foreign_message

    int32_foreign_message[2].c = 5

    msg.ClearField('map_int32_foreign_message')
    self.assertEqual(b'', msg.SerializeToString())
    self.assertTrue(2 in list(int32_foreign_message.keys())) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:14,代码来源:message_test.py

示例8: testMapValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMapValidAfterFieldCleared(self):
    # Map needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()
    int32_map = msg.map_int32_int32

    int32_map[2] = 4
    int32_map[3] = 6
    int32_map[4] = 8

    msg.ClearField('map_int32_int32')
    self.assertEqual(b'', msg.SerializeToString())
    matching_dict = {2: 4, 3: 6, 4: 8}
    self.assertMapIterEquals(int32_map.items(), matching_dict) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:17,代码来源:message_test.py

示例9: testMessageMapValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMessageMapValidAfterFieldCleared(self):
    # Map needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()
    int32_foreign_message = msg.map_int32_foreign_message

    int32_foreign_message[2].c = 5

    msg.ClearField('map_int32_foreign_message')
    self.assertEqual(b'', msg.SerializeToString())
    self.assertTrue(2 in int32_foreign_message.keys()) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:14,代码来源:message_test.py

示例10: testMapValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMapValidAfterFieldCleared(self):
    # Map needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()
    map = msg.map_int32_int32

    map[2] = 4
    map[3] = 6
    map[4] = 8

    msg.ClearField('map_int32_int32')
    matching_dict = {2: 4, 3: 6, 4: 8}
    self.assertMapIterEquals(list(map.items()), matching_dict) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:16,代码来源:message_test.py

示例11: testMapIterValidAfterFieldCleared

# 需要导入模块: from google.protobuf import message [as 别名]
# 或者: from google.protobuf.message import ClearField [as 别名]
def testMapIterValidAfterFieldCleared(self):
    # Map iterator needs to work even if field is cleared.
    # For the C++ implementation this tests the correctness of
    # ScalarMapContainer::Release()
    msg = map_unittest_pb2.TestMap()

    msg.map_int32_int32[2] = 4
    msg.map_int32_int32[3] = 6
    msg.map_int32_int32[4] = 8

    it = list(msg.map_int32_int32.items())

    msg.ClearField('map_int32_int32')
    matching_dict = {2: 4, 3: 6, 4: 8}
    self.assertMapIterEquals(it, matching_dict) 
开发者ID:sklearn-theano,项目名称:sklearn-theano,代码行数:17,代码来源:message_test.py


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