My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes  
Changes to /trunk/python/google/protobuf/internal/generator_test.py
r362 vs. r425 Compare: vs.  Format:
Revision r425
Go to: 
Project members, sign in to write a code review
/trunk/python/google/protobuf/internal/generator_test.py   r362 /trunk/python/google/protobuf/internal/generator_test.py   r425
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # 2 #
3 # Protocol Buffers - Google's data interchange format 3 # Protocol Buffers - Google's data interchange format
4 # Copyright 2008 Google Inc. All rights reserved. 4 # Copyright 2008 Google Inc. All rights reserved.
5 # http://code.google.com/p/protobuf/ 5 # http://code.google.com/p/protobuf/
6 # 6 #
7 # Redistribution and use in source and binary forms, with or without 7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions are 8 # modification, are permitted provided that the following conditions are
9 # met: 9 # met:
10 # 10 #
11 # * Redistributions of source code must retain the above copyright 11 # * Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer. 12 # notice, this list of conditions and the following disclaimer.
13 # * Redistributions in binary form must reproduce the above 13 # * Redistributions in binary form must reproduce the above
14 # copyright notice, this list of conditions and the following disclaimer 14 # copyright notice, this list of conditions and the following disclaimer
15 # in the documentation and/or other materials provided with the 15 # in the documentation and/or other materials provided with the
16 # distribution. 16 # distribution.
17 # * Neither the name of Google Inc. nor the names of its 17 # * Neither the name of Google Inc. nor the names of its
18 # contributors may be used to endorse or promote products derived from 18 # contributors may be used to endorse or promote products derived from
19 # this software without specific prior written permission. 19 # this software without specific prior written permission.
20 # 20 #
21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 24 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 26 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 32
33 # TODO(robinson): Flesh this out considerably. We focused on reflection_test.py 33 # TODO(robinson): Flesh this out considerably. We focused on reflection_test.py
34 # first, since it's testing the subtler code, and since it provides decent 34 # first, since it's testing the subtler code, and since it provides decent
35 # indirect testing of the protocol compiler output. 35 # indirect testing of the protocol compiler output.
36 36
37 """Unittest that directly tests the output of the pure-Python protocol 37 """Unittest that directly tests the output of the pure-Python protocol
38 compiler. See //google/protobuf/reflection_test.py for a test which 38 compiler. See //google/protobuf/reflection_test.py for a test which
39 further ensures that we can use Python protocol message objects as we expect. 39 further ensures that we can use Python protocol message objects as we expect.
40 """ 40 """
41 41
42 __author__ = 'robinson@google.com (Will Robinson)' 42 __author__ = 'robinson@google.com (Will Robinson)'
43 43
44 import unittest 44 import unittest
45 from google.protobuf.internal import test_bad_identifiers_pb2
45 from google.protobuf import unittest_custom_options_pb2 46 from google.protobuf import unittest_custom_options_pb2
46 from google.protobuf import unittest_import_pb2 47 from google.protobuf import unittest_import_pb2
48 from google.protobuf import unittest_import_public_pb2
47 from google.protobuf import unittest_mset_pb2 49 from google.protobuf import unittest_mset_pb2
48 from google.protobuf import unittest_pb2 50 from google.protobuf import unittest_pb2
49 from google.protobuf import unittest_no_generic_services_pb2 51 from google.protobuf import unittest_no_generic_services_pb2
50 from google.protobuf import service 52 from google.protobuf import service
51 53
52 MAX_EXTENSION = 536870912 54 MAX_EXTENSION = 536870912
53 55
54 56
55 class GeneratorTest(unittest.TestCase): 57 class GeneratorTest(unittest.TestCase):
56 58
57 def testNestedMessageDescriptor(self): 59 def testNestedMessageDescriptor(self):
58 field_name = 'optional_nested_message' 60 field_name = 'optional_nested_message'
59 proto_type = unittest_pb2.TestAllTypes 61 proto_type = unittest_pb2.TestAllTypes
60 self.assertEqual( 62 self.assertEqual(
61 proto_type.NestedMessage.DESCRIPTOR, 63 proto_type.NestedMessage.DESCRIPTOR,
62 proto_type.DESCRIPTOR.fields_by_name[field_name].message_type) 64 proto_type.DESCRIPTOR.fields_by_name[field_name].message_type)
63 65
64 def testEnums(self): 66 def testEnums(self):
65 # We test only module-level enums here. 67 # We test only module-level enums here.
66 # TODO(robinson): Examine descriptors directly to check 68 # TODO(robinson): Examine descriptors directly to check
67 # enum descriptor output. 69 # enum descriptor output.
68 self.assertEqual(4, unittest_pb2.FOREIGN_FOO) 70 self.assertEqual(4, unittest_pb2.FOREIGN_FOO)
69 self.assertEqual(5, unittest_pb2.FOREIGN_BAR) 71 self.assertEqual(5, unittest_pb2.FOREIGN_BAR)
70 self.assertEqual(6, unittest_pb2.FOREIGN_BAZ) 72 self.assertEqual(6, unittest_pb2.FOREIGN_BAZ)
71 73
72 proto = unittest_pb2.TestAllTypes() 74 proto = unittest_pb2.TestAllTypes()
73 self.assertEqual(1, proto.FOO) 75 self.assertEqual(1, proto.FOO)
74 self.assertEqual(1, unittest_pb2.TestAllTypes.FOO) 76 self.assertEqual(1, unittest_pb2.TestAllTypes.FOO)
75 self.assertEqual(2, proto.BAR) 77 self.assertEqual(2, proto.BAR)
76 self.assertEqual(2, unittest_pb2.TestAllTypes.BAR) 78 self.assertEqual(2, unittest_pb2.TestAllTypes.BAR)
77 self.assertEqual(3, proto.BAZ) 79 self.assertEqual(3, proto.BAZ)
78 self.assertEqual(3, unittest_pb2.TestAllTypes.BAZ) 80 self.assertEqual(3, unittest_pb2.TestAllTypes.BAZ)
79 81
80 def testExtremeDefaultValues(self): 82 def testExtremeDefaultValues(self):
81 message = unittest_pb2.TestExtremeDefaultValues() 83 message = unittest_pb2.TestExtremeDefaultValues()
82 84
83 # Python pre-2.6 does not have isinf() or isnan() functions, so we have 85 # Python pre-2.6 does not have isinf() or isnan() functions, so we have
84 # to provide our own. 86 # to provide our own.
85 def isnan(val): 87 def isnan(val):
86 # NaN is never equal to itself. 88 # NaN is never equal to itself.
87 return val != val 89 return val != val
88 def isinf(val): 90 def isinf(val):
89 # Infinity times zero equals NaN. 91 # Infinity times zero equals NaN.
90 return not isnan(val) and isnan(val * 0) 92 return not isnan(val) and isnan(val * 0)
91 93
92 self.assertTrue(isinf(message.inf_double)) 94 self.assertTrue(isinf(message.inf_double))
93 self.assertTrue(message.inf_double > 0) 95 self.assertTrue(message.inf_double > 0)
94 self.assertTrue(isinf(message.neg_inf_double)) 96 self.assertTrue(isinf(message.neg_inf_double))
95 self.assertTrue(message.neg_inf_double < 0) 97 self.assertTrue(message.neg_inf_double < 0)
96 self.assertTrue(isnan(message.nan_double)) 98 self.assertTrue(isnan(message.nan_double))
97 99
98 self.assertTrue(isinf(message.inf_float)) 100 self.assertTrue(isinf(message.inf_float))
99 self.assertTrue(message.inf_float > 0) 101 self.assertTrue(message.inf_float > 0)
100 self.assertTrue(isinf(message.neg_inf_float)) 102 self.assertTrue(isinf(message.neg_inf_float))
101 self.assertTrue(message.neg_inf_float < 0) 103 self.assertTrue(message.neg_inf_float < 0)
102 self.assertTrue(isnan(message.nan_float)) 104 self.assertTrue(isnan(message.nan_float))
103 self.assertEqual("? ? ?? ?? ??? ??/ ??-", message.cpp_trigraph) 105 self.assertEqual("? ? ?? ?? ??? ??/ ??-", message.cpp_trigraph)
104 106
105 def testHasDefaultValues(self): 107 def testHasDefaultValues(self):
106 desc = unittest_pb2.TestAllTypes.DESCRIPTOR 108 desc = unittest_pb2.TestAllTypes.DESCRIPTOR
107 109
108 expected_has_default_by_name = { 110 expected_has_default_by_name = {
109 'optional_int32': False, 111 'optional_int32': False,
110 'repeated_int32': False, 112 'repeated_int32': False,
111 'optional_nested_message': False, 113 'optional_nested_message': False,
112 'default_int32': True, 114 'default_int32': True,
113 } 115 }
114 116
115 has_default_by_name = dict( 117 has_default_by_name = dict(
116 [(f.name, f.has_default_value) 118 [(f.name, f.has_default_value)
117 for f in desc.fields 119 for f in desc.fields
118 if f.name in expected_has_default_by_name]) 120 if f.name in expected_has_default_by_name])
119 self.assertEqual(expected_has_default_by_name, has_default_by_name) 121 self.assertEqual(expected_has_default_by_name, has_default_by_name)
120 122
121 def testContainingTypeBehaviorForExtensions(self): 123 def testContainingTypeBehaviorForExtensions(self):
122 self.assertEqual(unittest_pb2.optional_int32_extension.containing_type, 124 self.assertEqual(unittest_pb2.optional_int32_extension.containing_type,
123 unittest_pb2.TestAllExtensions.DESCRIPTOR) 125 unittest_pb2.TestAllExtensions.DESCRIPTOR)
124 self.assertEqual(unittest_pb2.TestRequired.single.containing_type, 126 self.assertEqual(unittest_pb2.TestRequired.single.containing_type,
125 unittest_pb2.TestAllExtensions.DESCRIPTOR) 127 unittest_pb2.TestAllExtensions.DESCRIPTOR)
126 128
127 def testExtensionScope(self): 129 def testExtensionScope(self):
128 self.assertEqual(unittest_pb2.optional_int32_extension.extension_scope, 130 self.assertEqual(unittest_pb2.optional_int32_extension.extension_scope,
129 None) 131 None)
130 self.assertEqual(unittest_pb2.TestRequired.single.extension_scope, 132 self.assertEqual(unittest_pb2.TestRequired.single.extension_scope,
131 unittest_pb2.TestRequired.DESCRIPTOR) 133 unittest_pb2.TestRequired.DESCRIPTOR)
132 134
133 def testIsExtension(self): 135 def testIsExtension(self):
134 self.assertTrue(unittest_pb2.optional_int32_extension.is_extension) 136 self.assertTrue(unittest_pb2.optional_int32_extension.is_extension)
135 self.assertTrue(unittest_pb2.TestRequired.single.is_extension) 137 self.assertTrue(unittest_pb2.TestRequired.single.is_extension)
136 138
137 message_descriptor = unittest_pb2.TestRequired.DESCRIPTOR 139 message_descriptor = unittest_pb2.TestRequired.DESCRIPTOR
138 non_extension_descriptor = message_descriptor.fields_by_name['a'] 140 non_extension_descriptor = message_descriptor.fields_by_name['a']
139 self.assertTrue(not non_extension_descriptor.is_extension) 141 self.assertTrue(not non_extension_descriptor.is_extension)
140 142
141 def testOptions(self): 143 def testOptions(self):
142 proto = unittest_mset_pb2.TestMessageSet() 144 proto = unittest_mset_pb2.TestMessageSet()
143 self.assertTrue(proto.DESCRIPTOR.GetOptions().message_set_wire_format) 145 self.assertTrue(proto.DESCRIPTOR.GetOptions().message_set_wire_format)
144 146
145 def testMessageWithCustomOptions(self): 147 def testMessageWithCustomOptions(self):
146 proto = unittest_custom_options_pb2.TestMessageWithCustomOptions() 148 proto = unittest_custom_options_pb2.TestMessageWithCustomOptions()
147 enum_options = proto.DESCRIPTOR.enum_types_by_name['AnEnum'].GetOptions() 149 enum_options = proto.DESCRIPTOR.enum_types_by_name['AnEnum'].GetOptions()
148 self.assertTrue(enum_options is not None) 150 self.assertTrue(enum_options is not None)
149 # TODO(gps): We really should test for the presense of the enum_opt1 151 # TODO(gps): We really should test for the presense of the enum_opt1
150 # extension and for its value to be set to -789. 152 # extension and for its value to be set to -789.
151 153
152 def testNestedTypes(self): 154 def testNestedTypes(self):
153 self.assertEquals( 155 self.assertEquals(
154 set(unittest_pb2.TestAllTypes.DESCRIPTOR.nested_types), 156 set(unittest_pb2.TestAllTypes.DESCRIPTOR.nested_types),
155 set([ 157 set([
156 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR, 158 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR,
157 unittest_pb2.TestAllTypes.OptionalGroup.DESCRIPTOR, 159 unittest_pb2.TestAllTypes.OptionalGroup.DESCRIPTOR,
158 unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR, 160 unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR,
159 ])) 161 ]))
160 self.assertEqual(unittest_pb2.TestEmptyMessage.DESCRIPTOR.nested_types, []) 162 self.assertEqual(unittest_pb2.TestEmptyMessage.DESCRIPTOR.nested_types, [])
161 self.assertEqual( 163 self.assertEqual(
162 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.nested_types, []) 164 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.nested_types, [])
163 165
164 def testContainingType(self): 166 def testContainingType(self):
165 self.assertTrue( 167 self.assertTrue(
166 unittest_pb2.TestEmptyMessage.DESCRIPTOR.containing_type is None) 168 unittest_pb2.TestEmptyMessage.DESCRIPTOR.containing_type is None)
167 self.assertTrue( 169 self.assertTrue(
168 unittest_pb2.TestAllTypes.DESCRIPTOR.containing_type is None) 170 unittest_pb2.TestAllTypes.DESCRIPTOR.containing_type is None)
169 self.assertEqual( 171 self.assertEqual(
170 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type, 172 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type,
171 unittest_pb2.TestAllTypes.DESCRIPTOR) 173 unittest_pb2.TestAllTypes.DESCRIPTOR)
172 self.assertEqual( 174 self.assertEqual(
173 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type, 175 unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR.containing_type,
174 unittest_pb2.TestAllTypes.DESCRIPTOR) 176 unittest_pb2.TestAllTypes.DESCRIPTOR)
175 self.assertEqual( 177 self.assertEqual(
176 unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR.containing_type, 178 unittest_pb2.TestAllTypes.RepeatedGroup.DESCRIPTOR.containing_type,
177 unittest_pb2.TestAllTypes.DESCRIPTOR) 179 unittest_pb2.TestAllTypes.DESCRIPTOR)
178 180
179 def testContainingTypeInEnumDescriptor(self): 181 def testContainingTypeInEnumDescriptor(self):
180 self.assertTrue(unittest_pb2._FOREIGNENUM.containing_type is None) 182 self.assertTrue(unittest_pb2._FOREIGNENUM.containing_type is None)
181 self.assertEqual(unittest_pb2._TESTALLTYPES_NESTEDENUM.containing_type, 183 self.assertEqual(unittest_pb2._TESTALLTYPES_NESTEDENUM.containing_type,
182 unittest_pb2.TestAllTypes.DESCRIPTOR) 184 unittest_pb2.TestAllTypes.DESCRIPTOR)
183 185
184 def testPackage(self): 186 def testPackage(self):
185 self.assertEqual( 187 self.assertEqual(
186 unittest_pb2.TestAllTypes.DESCRIPTOR.file.package, 188 unittest_pb2.TestAllTypes.DESCRIPTOR.file.package,
187 'protobuf_unittest') 189 'protobuf_unittest')
188 desc = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR 190 desc = unittest_pb2.TestAllTypes.NestedMessage.DESCRIPTOR
189 self.assertEqual(desc.file.package, 'protobuf_unittest') 191 self.assertEqual(desc.file.package, 'protobuf_unittest')
190 self.assertEqual( 192 self.assertEqual(
191 unittest_import_pb2.ImportMessage.DESCRIPTOR.file.package, 193 unittest_import_pb2.ImportMessage.DESCRIPTOR.file.package,
192 'protobuf_unittest_import') 194 'protobuf_unittest_import')
193 195
194 self.assertEqual( 196 self.assertEqual(
195 unittest_pb2._FOREIGNENUM.file.package, 'protobuf_unittest') 197 unittest_pb2._FOREIGNENUM.file.package, 'protobuf_unittest')
196 self.assertEqual( 198 self.assertEqual(
197 unittest_pb2._TESTALLTYPES_NESTEDENUM.file.package, 199 unittest_pb2._TESTALLTYPES_NESTEDENUM.file.package,
198 'protobuf_unittest') 200 'protobuf_unittest')
199 self.assertEqual( 201 self.assertEqual(
200 unittest_import_pb2._IMPORTENUM.file.package, 202 unittest_import_pb2._IMPORTENUM.file.package,
201 'protobuf_unittest_import') 203 'protobuf_unittest_import')
202 204
203 def testExtensionRange(self): 205 def testExtensionRange(self):
204 self.assertEqual( 206 self.assertEqual(
205 unittest_pb2.TestAllTypes.DESCRIPTOR.extension_ranges, []) 207 unittest_pb2.TestAllTypes.DESCRIPTOR.extension_ranges, [])
206 self.assertEqual( 208 self.assertEqual(
207 unittest_pb2.TestAllExtensions.DESCRIPTOR.extension_ranges, 209 unittest_pb2.TestAllExtensions.DESCRIPTOR.extension_ranges,
208 [(1, MAX_EXTENSION)]) 210 [(1, MAX_EXTENSION)])
209 self.assertEqual( 211 self.assertEqual(
210 unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR.extension_ranges, 212 unittest_pb2.TestMultipleExtensionRanges.DESCRIPTOR.extension_ranges,
211 [(42, 43), (4143, 4244), (65536, MAX_EXTENSION)]) 213 [(42, 43), (4143, 4244), (65536, MAX_EXTENSION)])
212 214
213 def testFileDescriptor(self): 215 def testFileDescriptor(self):
214 self.assertEqual(unittest_pb2.DESCRIPTOR.name, 216 self.assertEqual(unittest_pb2.DESCRIPTOR.name,
215 'google/protobuf/unittest.proto') 217 'google/protobuf/unittest.proto')
216 self.assertEqual(unittest_pb2.DESCRIPTOR.package, 'protobuf_unittest') 218 self.assertEqual(unittest_pb2.DESCRIPTOR.package, 'protobuf_unittest')
217 self.assertFalse(unittest_pb2.DESCRIPTOR.serialized_pb is None) 219 self.assertFalse(unittest_pb2.DESCRIPTOR.serialized_pb is None)
218 220
219 def testNoGenericServices(self): 221 def testNoGenericServices(self):
220 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "TestMessage")) 222 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "TestMessage"))
221 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "FOO")) 223 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "FOO"))
222 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "test_extension")) 224 self.assertTrue(hasattr(unittest_no_generic_services_pb2, "test_extension"))
223 225
224 # Make sure unittest_no_generic_services_pb2 has no services subclassing 226 # Make sure unittest_no_generic_services_pb2 has no services subclassing
225 # Proto2 Service class. 227 # Proto2 Service class.
226 if hasattr(unittest_no_generic_services_pb2, "TestService"): 228 if hasattr(unittest_no_generic_services_pb2, "TestService"):
227 self.assertFalse(issubclass(unittest_no_generic_services_pb2.TestService, 229 self.assertFalse(issubclass(unittest_no_generic_services_pb2.TestService,
228 service.Service)) 230 service.Service))
229 231
230 def testMessageTypesByName(self): 232 def testMessageTypesByName(self):
231 file_type = unittest_pb2.DESCRIPTOR 233 file_type = unittest_pb2.DESCRIPTOR
232 self.assertEqual( 234 self.assertEqual(
233 unittest_pb2._TESTALLTYPES, 235 unittest_pb2._TESTALLTYPES,
234 file_type.message_types_by_name[unittest_pb2._TESTALLTYPES.name]) 236 file_type.message_types_by_name[unittest_pb2._TESTALLTYPES.name])
235 237
236 # Nested messages shouldn't be included in the message_types_by_name 238 # Nested messages shouldn't be included in the message_types_by_name
237 # dictionary (like in the C++ API). 239 # dictionary (like in the C++ API).
238 self.assertFalse( 240 self.assertFalse(
239 unittest_pb2._TESTALLTYPES_NESTEDMESSAGE.name in 241 unittest_pb2._TESTALLTYPES_NESTEDMESSAGE.name in
240 file_type.message_types_by_name) 242 file_type.message_types_by_name)
241 243
244 def testPublicImports(self):
245 # Test public imports as embedded message.
246 all_type_proto = unittest_pb2.TestAllTypes()
247 self.assertEqual(0, all_type_proto.optional_public_import_message.e)
248
249 # PublicImportMessage is actually defined in unittest_import_public_pb2
250 # module, and is public imported by unittest_import_pb2 module.
251 public_import_proto = unittest_import_pb2.PublicImportMessage()
252 self.assertEqual(0, public_import_proto.e)
253 self.assertTrue(unittest_import_public_pb2.PublicImportMessage is
254 unittest_import_pb2.PublicImportMessage)
255
256 def testBadIdentifiers(self):
257 # We're just testing that the code was imported without problems.
258 message = test_bad_identifiers_pb2.TestBadIdentifiers()
259 self.assertEqual(message.Extensions[test_bad_identifiers_pb2.message],
260 "foo")
261 self.assertEqual(message.Extensions[test_bad_identifiers_pb2.descriptor],
262 "bar")
263 self.assertEqual(message.Extensions[test_bad_identifiers_pb2.reflection],
264 "baz")
265 self.assertEqual(message.Extensions[test_bad_identifiers_pb2.service],
266 "qux")
242 267
243 if __name__ == '__main__': 268 if __name__ == '__main__':
244 unittest.main() 269 unittest.main()
Powered by Google Project Hosting