Python google.protobuf.message.oneof_string() Examples
The following are 15
code examples of google.protobuf.message.oneof_string().
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 also want to check out all available functions/classes of the module
google.protobuf.message
, or try the search function
.
Example #1
Source File: message_test.py From lambda-packs with MIT License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #2
Source File: message_test.py From lambda-packs with MIT License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = 'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #3
Source File: message_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #4
Source File: message_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = u'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #5
Source File: message_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #6
Source File: message_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = 'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #7
Source File: message_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #8
Source File: message_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = u'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #9
Source File: message_test.py From go2mapillary with GNU General Public License v3.0 | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #10
Source File: message_test.py From go2mapillary with GNU General Public License v3.0 | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = u'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #11
Source File: message_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #12
Source File: message_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = 'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #13
Source File: message_test.py From keras-lambda with MIT License | 5 votes |
def testOneofDefaultValues(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) # Oneof is set even when setting it to a default value. m.oneof_uint32 = 0 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) self.assertFalse(m.HasField('oneof_string')) m.oneof_string = "" self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_uint32'))
Example #14
Source File: message_test.py From keras-lambda with MIT License | 5 votes |
def testOneofSemantics(self, message_module): m = message_module.TestAllTypes() self.assertIs(None, m.WhichOneof('oneof_field')) m.oneof_uint32 = 11 self.assertEqual('oneof_uint32', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_uint32')) m.oneof_string = u'foo' self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_uint32')) self.assertTrue(m.HasField('oneof_string')) # Read nested message accessor without accessing submessage. m.oneof_nested_message self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) # Read accessor of nested message without accessing submessage. m.oneof_nested_message.bb self.assertEqual('oneof_string', m.WhichOneof('oneof_field')) self.assertTrue(m.HasField('oneof_string')) self.assertFalse(m.HasField('oneof_nested_message')) m.oneof_nested_message.bb = 11 self.assertEqual('oneof_nested_message', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_string')) self.assertTrue(m.HasField('oneof_nested_message')) m.oneof_bytes = b'bb' self.assertEqual('oneof_bytes', m.WhichOneof('oneof_field')) self.assertFalse(m.HasField('oneof_nested_message')) self.assertTrue(m.HasField('oneof_bytes'))
Example #15
Source File: message_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 4 votes |
def testPythonicInit(self): message = unittest_pb2.TestAllTypes( optional_int32=100, optional_fixed32=200, optional_float=300.5, optional_bytes=b'x', optionalgroup={'a': 400}, optional_nested_message={'bb': 500}, optional_nested_enum='BAZ', repeatedgroup=[{'a': 600}, {'a': 700}], repeated_nested_enum=['FOO', unittest_pb2.TestAllTypes.BAR], default_int32=800, oneof_string='y') self.assertIsInstance(message, unittest_pb2.TestAllTypes) self.assertEqual(100, message.optional_int32) self.assertEqual(200, message.optional_fixed32) self.assertEqual(300.5, message.optional_float) self.assertEqual(b'x', message.optional_bytes) self.assertEqual(400, message.optionalgroup.a) self.assertIsInstance(message.optional_nested_message, unittest_pb2.TestAllTypes.NestedMessage) self.assertEqual(500, message.optional_nested_message.bb) self.assertEqual(unittest_pb2.TestAllTypes.BAZ, message.optional_nested_enum) self.assertEqual(2, len(message.repeatedgroup)) self.assertEqual(600, message.repeatedgroup[0].a) self.assertEqual(700, message.repeatedgroup[1].a) self.assertEqual(2, len(message.repeated_nested_enum)) self.assertEqual(unittest_pb2.TestAllTypes.FOO, message.repeated_nested_enum[0]) self.assertEqual(unittest_pb2.TestAllTypes.BAR, message.repeated_nested_enum[1]) self.assertEqual(800, message.default_int32) self.assertEqual('y', message.oneof_string) self.assertFalse(message.HasField('optional_int64')) self.assertEqual(0, len(message.repeated_float)) self.assertEqual(42, message.default_int64) message = unittest_pb2.TestAllTypes(optional_nested_enum='BAZ') self.assertEqual(unittest_pb2.TestAllTypes.BAZ, message.optional_nested_enum) with self.assertRaises(ValueError): unittest_pb2.TestAllTypes( optional_nested_message={'INVALID_NESTED_FIELD': 17}) with self.assertRaises(TypeError): unittest_pb2.TestAllTypes( optional_nested_message={'bb': 'INVALID_VALUE_TYPE'}) with self.assertRaises(ValueError): unittest_pb2.TestAllTypes(optional_nested_enum='INVALID_LABEL') with self.assertRaises(ValueError): unittest_pb2.TestAllTypes(repeated_nested_enum='FOO') # Class to test proto3-only features/behavior (updated field presence & enums)