Initial import of v2.0.0beta
[protobuf.git] / python / google / protobuf / internal / descriptor_test.py
blob625d0326a235c050dc0f8ed09f26b06cd23da29f
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)'
21 import unittest
22 from google.protobuf import descriptor_pb2
23 from google.protobuf import descriptor
25 class DescriptorTest(unittest.TestCase):
27 def setUp(self):
28 self.my_enum = descriptor.EnumDescriptor(
29 name='ForeignEnum',
30 full_name='protobuf_unittest.ForeignEnum',
31 filename='ForeignEnum',
32 values=[
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(
38 name='NestedMessage',
39 full_name='protobuf_unittest.TestAllTypes.NestedMessage',
40 filename='some/filename/some.proto',
41 containing_type=None,
42 fields=[
43 descriptor.FieldDescriptor(
44 name='bb',
45 full_name='protobuf_unittest.TestAllTypes.NestedMessage.bb',
46 index=0, number=1,
47 type=5, cpp_type=1, label=1,
48 default_value=0,
49 message_type=None, enum_type=None, containing_type=None,
50 is_extension=False, extension_scope=None),
52 nested_types=[],
53 enum_types=[
54 self.my_enum,
56 extensions=[])
57 self.my_method = descriptor.MethodDescriptor(
58 name='Bar',
59 full_name='protobuf_unittest.TestService.Bar',
60 index=0,
61 containing_service=None,
62 input_type=None,
63 output_type=None)
64 self.my_service = descriptor.ServiceDescriptor(
65 name='TestServiceWithOptions',
66 full_name='protobuf_unittest.TestServiceWithOptions',
67 index=0,
68 methods=[
69 self.my_method
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__':
97 unittest.main()