本文整理汇总了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'))
示例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
示例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'))
示例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'))
示例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'))
示例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)
示例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()))
示例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)
示例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())
示例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)
示例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)