Python google.protobuf.message.ClearField() Examples
The following are 30 code examples for showing how to use google.protobuf.message.ClearField(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
google.protobuf.message
, or try the search function
.
Example 1
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 6 votes |
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'))
Example 2
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 6 votes |
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
Example 3
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 6 votes |
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'))
Example 4
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 6 votes |
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
Example 5
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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'))
Example 6
Project: coremltools Author: apple File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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'))
Example 7
Project: coremltools Author: apple File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 6 votes |
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
Example 8
Project: go2mapillary Author: enricofer File: message_test.py License: GNU General Public License v3.0 | 6 votes |
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'))
Example 9
Project: go2mapillary Author: enricofer File: message_test.py License: GNU General Public License v3.0 | 6 votes |
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
Example 10
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: message_test.py License: MIT License | 6 votes |
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'))
Example 11
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: message_test.py License: MIT License | 6 votes |
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
Example 12
Project: keras-lambda Author: sunilmallya File: message_test.py License: MIT License | 6 votes |
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'))
Example 13
Project: keras-lambda Author: sunilmallya File: message_test.py License: MIT License | 6 votes |
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
Example 14
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 5 votes |
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'))
Example 15
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 5 votes |
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'))
Example 16
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 5 votes |
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'))
Example 17
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 5 votes |
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)
Example 18
Project: lambda-packs Author: ryfeus File: message_test.py License: MIT License | 5 votes |
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()))
Example 19
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 5 votes |
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'))
Example 20
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 5 votes |
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'))
Example 21
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 5 votes |
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'))
Example 22
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 5 votes |
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)
Example 23
Project: auto-alt-text-lambda-api Author: abhisuri97 File: message_test.py License: MIT License | 5 votes |
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())
Example 24
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))
Example 25
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))
Example 26
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))
Example 27
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 28
Project: sklearn-theano Author: sklearn-theano File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example 29
Project: coremltools Author: apple File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))
Example 30
Project: coremltools Author: apple File: message_test.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
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'))