| Index: third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
|
| diff --git a/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py b/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
|
| index 2fbe5ea7ac23383537aca0a35a099f003b630510..7bb7d1acecd62ab9db85b7b07c6209cb199939f9 100644
|
| --- a/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
|
| +++ b/third_party/protobuf/python/google/protobuf/internal/message_factory_test.py
|
| @@ -35,9 +35,10 @@
|
| __author__ = 'matthewtoia@google.com (Matt Toia)'
|
|
|
| try:
|
| - import unittest2 as unittest
|
| + import unittest2 as unittest #PY26
|
| except ImportError:
|
| import unittest
|
| +
|
| from google.protobuf import descriptor_pb2
|
| from google.protobuf.internal import factory_test1_pb2
|
| from google.protobuf.internal import factory_test2_pb2
|
| @@ -130,6 +131,60 @@ class MessageFactoryTest(unittest.TestCase):
|
| self.assertEqual('test1', msg1.Extensions[ext1])
|
| self.assertEqual('test2', msg1.Extensions[ext2])
|
|
|
| + def testDuplicateExtensionNumber(self):
|
| + pool = descriptor_pool.DescriptorPool()
|
| + factory = message_factory.MessageFactory(pool=pool)
|
| +
|
| + # Add Container message.
|
| + f = descriptor_pb2.FileDescriptorProto()
|
| + f.name = 'google/protobuf/internal/container.proto'
|
| + f.package = 'google.protobuf.python.internal'
|
| + msg = f.message_type.add()
|
| + msg.name = 'Container'
|
| + rng = msg.extension_range.add()
|
| + rng.start = 1
|
| + rng.end = 10
|
| + pool.Add(f)
|
| + msgs = factory.GetMessages([f.name])
|
| + self.assertIn('google.protobuf.python.internal.Container', msgs)
|
| +
|
| + # Extend container.
|
| + f = descriptor_pb2.FileDescriptorProto()
|
| + f.name = 'google/protobuf/internal/extension.proto'
|
| + f.package = 'google.protobuf.python.internal'
|
| + f.dependency.append('google/protobuf/internal/container.proto')
|
| + msg = f.message_type.add()
|
| + msg.name = 'Extension'
|
| + ext = msg.extension.add()
|
| + ext.name = 'extension_field'
|
| + ext.number = 2
|
| + ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
|
| + ext.type_name = 'Extension'
|
| + ext.extendee = 'Container'
|
| + pool.Add(f)
|
| + msgs = factory.GetMessages([f.name])
|
| + self.assertIn('google.protobuf.python.internal.Extension', msgs)
|
| +
|
| + # Add Duplicate extending the same field number.
|
| + f = descriptor_pb2.FileDescriptorProto()
|
| + f.name = 'google/protobuf/internal/duplicate.proto'
|
| + f.package = 'google.protobuf.python.internal'
|
| + f.dependency.append('google/protobuf/internal/container.proto')
|
| + msg = f.message_type.add()
|
| + msg.name = 'Duplicate'
|
| + ext = msg.extension.add()
|
| + ext.name = 'extension_field'
|
| + ext.number = 2
|
| + ext.label = descriptor_pb2.FieldDescriptorProto.LABEL_OPTIONAL
|
| + ext.type_name = 'Duplicate'
|
| + ext.extendee = 'Container'
|
| + pool.Add(f)
|
| +
|
| + with self.assertRaises(Exception) as cm:
|
| + factory.GetMessages([f.name])
|
| +
|
| + self.assertIsInstance(cm.exception, (AssertionError, ValueError))
|
| +
|
|
|
| if __name__ == '__main__':
|
| unittest.main()
|
|
|