Python google.protobuf.descriptor.MakeDescriptor() Examples
The following are 30
code examples of google.protobuf.descriptor.MakeDescriptor().
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.descriptor
, or try the search function
.
Example #1
Source File: reflection_test.py From go2mapillary with GNU General Public License v3.0 | 7 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #2
Source File: reflection_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #3
Source File: descriptor_test.py From keras-lambda with MIT License | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #4
Source File: reflection_test.py From keras-lambda with MIT License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #5
Source File: reflection_test.py From keras-lambda with MIT License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #6
Source File: descriptor_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #7
Source File: reflection_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #8
Source File: reflection_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #9
Source File: descriptor_test.py From go2mapillary with GNU General Public License v3.0 | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #10
Source File: reflection_test.py From go2mapillary with GNU General Public License v3.0 | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #11
Source File: descriptor_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #12
Source File: reflection_test.py From coremltools with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #13
Source File: reflection_test.py From botchallenge with MIT License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #14
Source File: reflection_test.py From botchallenge with MIT License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(message.Message, metaclass=reflection.GeneratedProtocolMessageType): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #15
Source File: reflection_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #16
Source File: reflection_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #17
Source File: descriptor_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #18
Source File: reflection_test.py From lambda-packs with MIT License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #19
Source File: reflection_test.py From lambda-packs with MIT License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #20
Source File: descriptor_test.py From lambda-packs with MIT License | 6 votes |
def testJsonName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'TestJsonName' names = ['field_name', 'fieldName', 'FieldName', '_field_name', 'FIELD_NAME', 'json_name'] json_names = ['fieldName', 'fieldName', 'FieldName', 'FieldName', 'FIELDNAME', '@type'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] field.json_name = '@type' result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(json_names)): self.assertEqual(result.fields[index].json_name, json_names[index])
Example #21
Source File: reflection_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testParsingFlatClassWithExplicitClassDeclaration(self): """Test that the generated class can parse a flat message.""" # TODO(xiaofeng): This test fails with cpp implemetnation in the call # of six.with_metaclass(). The other two callsites of with_metaclass # in this file are both excluded from cpp test, so it might be expected # to fail. Need someone more familiar with the python code to take a # look at this. if api_implementation.Type() != 'python': return file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('A')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) class MessageClass(six.with_metaclass(reflection.GeneratedProtocolMessageType, message.Message)): DESCRIPTOR = msg_descriptor msg = MessageClass() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #22
Source File: reflection_test.py From auto-alt-text-lambda-api with MIT License | 6 votes |
def testParsingNestedClass(self): """Test that the generated class can parse a nested message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('C')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'bar {' ' baz {' ' deep: 4' ' }' '}') text_format.Merge(msg_str, msg) self.assertEqual(msg.bar.baz.deep, 4)
Example #23
Source File: descriptor_test.py From auto-alt-text-lambda-api with MIT License | 5 votes |
def testMakeDescriptorWithOptions(self): descriptor_proto = descriptor_pb2.DescriptorProto() aggregate_message = unittest_custom_options_pb2.AggregateMessage aggregate_message.DESCRIPTOR.CopyToProto(descriptor_proto) reformed_descriptor = descriptor.MakeDescriptor(descriptor_proto) options = reformed_descriptor.GetOptions() self.assertEqual(101, options.Extensions[unittest_custom_options_pb2.msgopt].i)
Example #24
Source File: descriptor_test.py From keras-lambda with MIT License | 5 votes |
def testCamelcaseName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'Bar' names = ['foo_foo', 'FooBar', 'fooBaz', 'fooFoo', 'foobar'] camelcase_names = ['fooFoo', 'fooBar', 'fooBaz', 'fooFoo', 'foobar'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(camelcase_names)): self.assertEqual(result.fields[index].camelcase_name, camelcase_names[index])
Example #25
Source File: descriptor_test.py From keras-lambda with MIT License | 5 votes |
def testMakeDescriptorWithOptions(self): descriptor_proto = descriptor_pb2.DescriptorProto() aggregate_message = unittest_custom_options_pb2.AggregateMessage aggregate_message.DESCRIPTOR.CopyToProto(descriptor_proto) reformed_descriptor = descriptor.MakeDescriptor(descriptor_proto) options = reformed_descriptor.GetOptions() self.assertEqual(101, options.Extensions[unittest_custom_options_pb2.msgopt].i)
Example #26
Source File: reflection_test.py From lambda-packs with MIT License | 5 votes |
def testParsingFlatClass(self): """Test that the generated class can parse a flat message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('B')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #27
Source File: reflection_test.py From keras-lambda with MIT License | 5 votes |
def testParsingFlatClass(self): """Test that the generated class can parse a flat message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('B')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #28
Source File: reflection_test.py From sklearn-theano with BSD 3-Clause "New" or "Revised" License | 5 votes |
def testParsingFlatClass(self): """Test that the generated class can parse a flat message.""" file_descriptor = descriptor_pb2.FileDescriptorProto() file_descriptor.ParseFromString(self._GetSerializedFileDescriptor('B')) msg_descriptor = descriptor.MakeDescriptor( file_descriptor.message_type[0]) msg_class = reflection.MakeClass(msg_descriptor) msg = msg_class() msg_str = ( 'flat: 0 ' 'flat: 1 ' 'flat: 2 ') text_format.Merge(msg_str, msg) self.assertEqual(msg.flat, [0, 1, 2])
Example #29
Source File: descriptor_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def testCamelcaseName(self): descriptor_proto = descriptor_pb2.DescriptorProto() descriptor_proto.name = 'Bar' names = ['foo_foo', 'FooBar', 'fooBaz', 'fooFoo', 'foobar'] camelcase_names = ['fooFoo', 'fooBar', 'fooBaz', 'fooFoo', 'foobar'] for index in range(len(names)): field = descriptor_proto.field.add() field.number = index + 1 field.name = names[index] result = descriptor.MakeDescriptor(descriptor_proto) for index in range(len(camelcase_names)): self.assertEqual(result.fields[index].camelcase_name, camelcase_names[index])
Example #30
Source File: descriptor_test.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
def testMakeDescriptorWithOptions(self): descriptor_proto = descriptor_pb2.DescriptorProto() aggregate_message = unittest_custom_options_pb2.AggregateMessage aggregate_message.DESCRIPTOR.CopyToProto(descriptor_proto) reformed_descriptor = descriptor.MakeDescriptor(descriptor_proto) options = reformed_descriptor.GetOptions() self.assertEqual(101, options.Extensions[unittest_custom_options_pb2.msgopt].i)