1 # Protocol Buffers - Google's data interchange format
2 # Copyright 2008 Google Inc.
3 # http://code.google.com/p/protobuf/
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 """Unittest for google.protobuf.internal.descriptor."""
19 __author__
= 'robinson@google.com (Will Robinson)'
22 from google
.protobuf
import descriptor_pb2
23 from google
.protobuf
import descriptor
25 class DescriptorTest(unittest
.TestCase
):
28 self
.my_enum
= descriptor
.EnumDescriptor(
30 full_name
='protobuf_unittest.ForeignEnum',
31 filename
='ForeignEnum',
33 descriptor
.EnumValueDescriptor(name
='FOREIGN_FOO', index
=0, number
=4),
34 descriptor
.EnumValueDescriptor(name
='FOREIGN_BAR', index
=1, number
=5),
35 descriptor
.EnumValueDescriptor(name
='FOREIGN_BAZ', index
=2, number
=6),
37 self
.my_message
= descriptor
.Descriptor(
39 full_name
='protobuf_unittest.TestAllTypes.NestedMessage',
40 filename
='some/filename/some.proto',
43 descriptor
.FieldDescriptor(
45 full_name
='protobuf_unittest.TestAllTypes.NestedMessage.bb',
47 type=5, cpp_type
=1, label
=1,
49 message_type
=None, enum_type
=None, containing_type
=None,
50 is_extension
=False, extension_scope
=None),
57 self
.my_method
= descriptor
.MethodDescriptor(
59 full_name
='protobuf_unittest.TestService.Bar',
61 containing_service
=None,
64 self
.my_service
= descriptor
.ServiceDescriptor(
65 name
='TestServiceWithOptions',
66 full_name
='protobuf_unittest.TestServiceWithOptions',
72 def testEnumFixups(self
):
73 self
.assertEqual(self
.my_enum
, self
.my_enum
.values
[0].type)
75 def testContainingTypeFixups(self
):
76 self
.assertEqual(self
.my_message
, self
.my_message
.fields
[0].containing_type
)
77 self
.assertEqual(self
.my_message
, self
.my_enum
.containing_type
)
79 def testContainingServiceFixups(self
):
80 self
.assertEqual(self
.my_service
, self
.my_method
.containing_service
)
82 def testGetOptions(self
):
83 self
.assertEqual(self
.my_enum
.GetOptions(),
84 descriptor_pb2
.EnumOptions())
85 self
.assertEqual(self
.my_enum
.values
[0].GetOptions(),
86 descriptor_pb2
.EnumValueOptions())
87 self
.assertEqual(self
.my_message
.GetOptions(),
88 descriptor_pb2
.MessageOptions())
89 self
.assertEqual(self
.my_message
.fields
[0].GetOptions(),
90 descriptor_pb2
.FieldOptions())
91 self
.assertEqual(self
.my_method
.GetOptions(),
92 descriptor_pb2
.MethodOptions())
93 self
.assertEqual(self
.my_service
.GetOptions(),
94 descriptor_pb2
.ServiceOptions())
96 if __name__
== '__main__':