本文整理匯總了Python中google.protobuf.unittest_custom_options_pb2.DESCRIPTOR屬性的典型用法代碼示例。如果您正苦於以下問題:Python unittest_custom_options_pb2.DESCRIPTOR屬性的具體用法?Python unittest_custom_options_pb2.DESCRIPTOR怎麽用?Python unittest_custom_options_pb2.DESCRIPTOR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類google.protobuf.unittest_custom_options_pb2
的用法示例。
在下文中一共展示了unittest_custom_options_pb2.DESCRIPTOR屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testNestedOptions
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testNestedOptions(self):
nested_message =\
unittest_custom_options_pb2.NestedOptionType.NestedMessage.DESCRIPTOR
self.assertEqual(1001, nested_message.GetOptions().Extensions[
unittest_custom_options_pb2.message_opt1])
nested_field = nested_message.fields_by_name["nested_field"]
self.assertEqual(1002, nested_field.GetOptions().Extensions[
unittest_custom_options_pb2.field_opt1])
outer_message =\
unittest_custom_options_pb2.NestedOptionType.DESCRIPTOR
nested_enum = outer_message.enum_types_by_name["NestedEnum"]
self.assertEqual(1003, nested_enum.GetOptions().Extensions[
unittest_custom_options_pb2.enum_opt1])
nested_enum_value = outer_message.enum_values_by_name["NESTED_ENUM_VALUE"]
self.assertEqual(1004, nested_enum_value.GetOptions().Extensions[
unittest_custom_options_pb2.enum_value_opt1])
nested_extension = outer_message.extensions_by_name["nested_extension"]
self.assertEqual(1005, nested_extension.GetOptions().Extensions[
unittest_custom_options_pb2.field_opt2])
示例2: CheckFieldDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def CheckFieldDescriptor(self, field_descriptor):
# Basic properties
self.assertEqual(field_descriptor.name, 'optional_int32')
self.assertEqual(field_descriptor.camelcase_name, 'optionalInt32')
self.assertEqual(field_descriptor.full_name,
'protobuf_unittest.TestAllTypes.optional_int32')
self.assertEqual(field_descriptor.containing_type.name, 'TestAllTypes')
self.assertEqual(field_descriptor.file, unittest_pb2.DESCRIPTOR)
# Test equality and hashability
self.assertEqual(field_descriptor, field_descriptor)
self.assertEqual(
field_descriptor.containing_type.fields_by_name['optional_int32'],
field_descriptor)
self.assertEqual(
field_descriptor.containing_type.fields_by_camelcase_name[
'optionalInt32'],
field_descriptor)
self.assertIn(field_descriptor, [field_descriptor])
self.assertIn(field_descriptor, {field_descriptor: None})
self.assertEqual(None, field_descriptor.extension_scope)
self.assertEqual(None, field_descriptor.enum_type)
if api_implementation.Type() == 'cpp':
# For test coverage only
self.assertEqual(field_descriptor.id, field_descriptor.id)
示例3: testDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testDescriptor(self):
message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
self.CheckMessageDescriptor(message_descriptor)
field_descriptor = message_descriptor.fields_by_name['optional_int32']
self.CheckFieldDescriptor(field_descriptor)
field_descriptor = message_descriptor.fields_by_camelcase_name[
'optionalInt32']
self.CheckFieldDescriptor(field_descriptor)
enum_descriptor = unittest_pb2.DESCRIPTOR.enum_types_by_name[
'ForeignEnum']
self.assertEqual(None, enum_descriptor.containing_type)
# Test extension range
self.assertEqual(
unittest_pb2.TestAllExtensions.DESCRIPTOR.extension_ranges,
[(1, 536870912)])
self.assertEqual(
unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR.extension_ranges,
[(42, 43), (4143, 4244), (65536, 536870912)])
示例4: testCopyToProto_ForeignNestedMessage
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_ForeignNestedMessage(self):
TEST_FOREIGN_NESTED_ASCII = """
name: 'TestForeignNested'
field: <
name: 'foreign_nested'
number: 1
label: 1 # Optional
type: 11 # TYPE_MESSAGE
type_name: '.protobuf_unittest.TestAllTypes.NestedMessage'
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestForeignNested.DESCRIPTOR,
descriptor_pb2.DescriptorProto,
TEST_FOREIGN_NESTED_ASCII)
示例5: testCopyToProto_SeveralExtensions
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_SeveralExtensions(self):
TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII = """
name: 'TestMultipleExtensionRanges'
extension_range: <
start: 42
end: 43
>
extension_range: <
start: 4143
end: 4244
>
extension_range: <
start: 65536
end: 536870912
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR,
descriptor_pb2.DescriptorProto,
TEST_MESSAGE_WITH_SEVERAL_EXTENSIONS_ASCII)
示例6: testCopyToProto_ServiceDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_ServiceDescriptor(self):
TEST_SERVICE_ASCII = """
name: 'TestService'
method: <
name: 'Foo'
input_type: '.protobuf_unittest.FooRequest'
output_type: '.protobuf_unittest.FooResponse'
>
method: <
name: 'Bar'
input_type: '.protobuf_unittest.BarRequest'
output_type: '.protobuf_unittest.BarResponse'
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestService.DESCRIPTOR,
descriptor_pb2.ServiceDescriptorProto,
TEST_SERVICE_ASCII)
示例7: testCopyToProto_ForeignEnum
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_ForeignEnum(self):
TEST_FOREIGN_ENUM_ASCII = """
name: 'ForeignEnum'
value: <
name: 'FOREIGN_FOO'
number: 4
>
value: <
name: 'FOREIGN_BAR'
number: 5
>
value: <
name: 'FOREIGN_BAZ'
number: 6
>
"""
self._InternalTestCopyToProto(
unittest_pb2.ForeignEnum.DESCRIPTOR,
descriptor_pb2.EnumDescriptorProto,
TEST_FOREIGN_ENUM_ASCII)
示例8: testCopyToProto_Options
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_Options(self):
TEST_DEPRECATED_FIELDS_ASCII = """
name: 'TestDeprecatedFields'
field: <
name: 'deprecated_int32'
number: 1
label: 1 # Optional
type: 5 # TYPE_INT32
options: <
deprecated: true
>
>
"""
self._InternalTestCopyToProto(
unittest_pb2.TestDeprecatedFields.DESCRIPTOR,
descriptor_pb2.DescriptorProto,
TEST_DEPRECATED_FIELDS_ASCII)
示例9: testCopyToProto_ServiceDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_ServiceDescriptor(self):
TEST_SERVICE_ASCII = """
name: 'TestService'
method: <
name: 'Foo'
input_type: '.protobuf_unittest.FooRequest'
output_type: '.protobuf_unittest.FooResponse'
>
method: <
name: 'Bar'
input_type: '.protobuf_unittest.BarRequest'
output_type: '.protobuf_unittest.BarResponse'
>
"""
# TODO(rocking): enable this test after the proto descriptor change is
# checked in.
#self._InternalTestCopyToProto(
# unittest_pb2.TestService.DESCRIPTOR,
# descriptor_pb2.ServiceDescriptorProto,
# TEST_SERVICE_ASCII)
示例10: testFileDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testFileDescriptor(self):
self.assertEqual(self.my_file.name, 'some/filename/some.proto')
self.assertEqual(self.my_file.package, 'protobuf_unittest')
self.assertEqual(self.my_file.pool, self.pool)
self.assertFalse(self.my_file.has_options)
self.assertEqual('proto2', self.my_file.syntax)
file_proto = descriptor_pb2.FileDescriptorProto()
self.my_file.CopyToProto(file_proto)
self.assertEqual(self.my_file.serialized_pb,
file_proto.SerializeToString())
# Generated modules also belong to the default pool.
self.assertEqual(unittest_pb2.DESCRIPTOR.pool, descriptor_pool.Default())
示例11: CheckDescriptorSequence
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def CheckDescriptorSequence(self, sequence):
# Verifies that a property like 'messageDescriptor.fields' has all the
# properties of an immutable abc.Sequence.
self.assertNotEqual(sequence,
unittest_pb2.TestAllExtensions.DESCRIPTOR.fields)
self.assertNotEqual(sequence, [])
self.assertNotEqual(sequence, 1)
self.assertFalse(sequence == 1) # Only for cpp test coverage
self.assertEqual(sequence, sequence)
expected_list = list(sequence)
self.assertEqual(expected_list, sequence)
self.assertGreater(len(sequence), 0) # Sized
self.assertEqual(len(sequence), len(expected_list)) # Iterable
self.assertEqual(sequence[len(sequence) -1], sequence[-1])
item = sequence[0]
self.assertEqual(item, sequence[0])
self.assertIn(item, sequence) # Container
self.assertEqual(sequence.index(item), 0)
self.assertEqual(sequence.count(item), 1)
other_item = unittest_pb2.NestedTestAllTypes.DESCRIPTOR.fields[0]
self.assertNotIn(other_item, sequence)
self.assertEqual(sequence.count(other_item), 0)
self.assertRaises(ValueError, sequence.index, other_item)
self.assertRaises(ValueError, sequence.index, [])
reversed_iterator = reversed(sequence)
self.assertEqual(list(reversed_iterator), list(sequence)[::-1])
self.assertRaises(StopIteration, next, reversed_iterator)
expected_list[0] = 'change value'
self.assertNotEqual(expected_list, sequence)
# TODO(jieluo): Change __repr__ support for DescriptorSequence.
if api_implementation.Type() == 'python':
self.assertEqual(str(list(sequence)), str(sequence))
else:
self.assertEqual(str(sequence)[0], '<')
示例12: testCppDescriptorContainer
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCppDescriptorContainer(self):
containing_file = unittest_pb2.DESCRIPTOR
self.CheckDescriptorSequence(containing_file.dependencies)
self.CheckDescriptorMapping(containing_file.message_types_by_name)
self.CheckDescriptorMapping(containing_file.enum_types_by_name)
self.CheckDescriptorMapping(containing_file.services_by_name)
self.CheckDescriptorMapping(containing_file.extensions_by_name)
self.CheckDescriptorMapping(
unittest_pb2.TestNestedExtension.DESCRIPTOR.extensions_by_name)
示例13: testServiceDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testServiceDescriptor(self):
service_descriptor = unittest_pb2.DESCRIPTOR.services_by_name['TestService']
self.assertEqual(service_descriptor.name, 'TestService')
self.assertEqual(service_descriptor.methods[0].name, 'Foo')
self.assertIs(service_descriptor.file, unittest_pb2.DESCRIPTOR)
self.assertEqual(service_descriptor.index, 0)
self.CheckDescriptorMapping(service_descriptor.methods_by_name)
示例14: testOneofDescriptor
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testOneofDescriptor(self):
message_descriptor = unittest_pb2.TestAllTypes.DESCRIPTOR
oneof_descriptor = message_descriptor.oneofs_by_name['oneof_field']
self.assertFalse(oneof_descriptor.has_options)
self.assertEqual(message_descriptor, oneof_descriptor.containing_type)
self.assertEqual('oneof_field', oneof_descriptor.name)
self.assertEqual('protobuf_unittest.TestAllTypes.oneof_field',
oneof_descriptor.full_name)
self.assertEqual(0, oneof_descriptor.index)
示例15: testCopyToProto_EmptyMessage
# 需要導入模塊: from google.protobuf import unittest_custom_options_pb2 [as 別名]
# 或者: from google.protobuf.unittest_custom_options_pb2 import DESCRIPTOR [as 別名]
def testCopyToProto_EmptyMessage(self):
self._InternalTestCopyToProto(
unittest_pb2.TestEmptyMessage.DESCRIPTOR,
descriptor_pb2.DescriptorProto,
TEST_EMPTY_MESSAGE_DESCRIPTOR_ASCII)