當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。