OLD | NEW |
1 #! /usr/bin/env python | 1 #! /usr/bin/env 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 # https://developers.google.com/protocol-buffers/ | 5 # https://developers.google.com/protocol-buffers/ |
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 # |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 # performed twice because multiple calls with the same input must be allowed | 107 # performed twice because multiple calls with the same input must be allowed |
108 for _ in range(2): | 108 for _ in range(2): |
109 messages = message_factory.GetMessages([self.factory_test1_fd, | 109 messages = message_factory.GetMessages([self.factory_test1_fd, |
110 self.factory_test2_fd]) | 110 self.factory_test2_fd]) |
111 self.assertTrue( | 111 self.assertTrue( |
112 set(['google.protobuf.python.internal.Factory2Message', | 112 set(['google.protobuf.python.internal.Factory2Message', |
113 'google.protobuf.python.internal.Factory1Message'], | 113 'google.protobuf.python.internal.Factory1Message'], |
114 ).issubset(set(messages.keys()))) | 114 ).issubset(set(messages.keys()))) |
115 self._ExerciseDynamicClass( | 115 self._ExerciseDynamicClass( |
116 messages['google.protobuf.python.internal.Factory2Message']) | 116 messages['google.protobuf.python.internal.Factory2Message']) |
| 117 self.assertTrue( |
| 118 set(['google.protobuf.python.internal.Factory2Message.one_more_field', |
| 119 'google.protobuf.python.internal.another_field'], |
| 120 ).issubset( |
| 121 set(messages['google.protobuf.python.internal.Factory1Message'] |
| 122 ._extensions_by_name.keys()))) |
117 factory_msg1 = messages['google.protobuf.python.internal.Factory1Message'] | 123 factory_msg1 = messages['google.protobuf.python.internal.Factory1Message'] |
118 self.assertTrue(set( | |
119 ['google.protobuf.python.internal.Factory2Message.one_more_field', | |
120 'google.protobuf.python.internal.another_field'],).issubset(set( | |
121 ext.full_name | |
122 for ext in factory_msg1.DESCRIPTOR.file.pool.FindAllExtensions( | |
123 factory_msg1.DESCRIPTOR)))) | |
124 msg1 = messages['google.protobuf.python.internal.Factory1Message']() | 124 msg1 = messages['google.protobuf.python.internal.Factory1Message']() |
125 ext1 = msg1.Extensions._FindExtensionByName( | 125 ext1 = factory_msg1._extensions_by_name[ |
126 'google.protobuf.python.internal.Factory2Message.one_more_field') | 126 'google.protobuf.python.internal.Factory2Message.one_more_field'] |
127 ext2 = msg1.Extensions._FindExtensionByName( | 127 ext2 = factory_msg1._extensions_by_name[ |
128 'google.protobuf.python.internal.another_field') | 128 'google.protobuf.python.internal.another_field'] |
129 msg1.Extensions[ext1] = 'test1' | 129 msg1.Extensions[ext1] = 'test1' |
130 msg1.Extensions[ext2] = 'test2' | 130 msg1.Extensions[ext2] = 'test2' |
131 self.assertEqual('test1', msg1.Extensions[ext1]) | 131 self.assertEqual('test1', msg1.Extensions[ext1]) |
132 self.assertEqual('test2', msg1.Extensions[ext2]) | 132 self.assertEqual('test2', msg1.Extensions[ext2]) |
133 | 133 |
134 def testDuplicateExtensionNumber(self): | 134 def testDuplicateExtensionNumber(self): |
135 pool = descriptor_pool.DescriptorPool() | 135 pool = descriptor_pool.DescriptorPool() |
136 factory = message_factory.MessageFactory(pool=pool) | 136 factory = message_factory.MessageFactory(pool=pool) |
137 | 137 |
138 # Add Container message. | 138 # Add Container message. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 pool.Add(f) | 181 pool.Add(f) |
182 | 182 |
183 with self.assertRaises(Exception) as cm: | 183 with self.assertRaises(Exception) as cm: |
184 factory.GetMessages([f.name]) | 184 factory.GetMessages([f.name]) |
185 | 185 |
186 self.assertIsInstance(cm.exception, (AssertionError, ValueError)) | 186 self.assertIsInstance(cm.exception, (AssertionError, ValueError)) |
187 | 187 |
188 | 188 |
189 if __name__ == '__main__': | 189 if __name__ == '__main__': |
190 unittest.main() | 190 unittest.main() |
OLD | NEW |