| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 from google.protobuf import unittest_import_pb2 | 45 from google.protobuf import unittest_import_pb2 |
| 46 from google.protobuf import unittest_import_public_pb2 | 46 from google.protobuf import unittest_import_public_pb2 |
| 47 from google.protobuf import unittest_pb2 | 47 from google.protobuf import unittest_pb2 |
| 48 from google.protobuf import descriptor_pb2 | 48 from google.protobuf import descriptor_pb2 |
| 49 from google.protobuf.internal import api_implementation | 49 from google.protobuf.internal import api_implementation |
| 50 from google.protobuf.internal import descriptor_pool_test1_pb2 | 50 from google.protobuf.internal import descriptor_pool_test1_pb2 |
| 51 from google.protobuf.internal import descriptor_pool_test2_pb2 | 51 from google.protobuf.internal import descriptor_pool_test2_pb2 |
| 52 from google.protobuf.internal import factory_test1_pb2 | 52 from google.protobuf.internal import factory_test1_pb2 |
| 53 from google.protobuf.internal import factory_test2_pb2 | 53 from google.protobuf.internal import factory_test2_pb2 |
| 54 from google.protobuf.internal import file_options_test_pb2 |
| 54 from google.protobuf.internal import more_messages_pb2 | 55 from google.protobuf.internal import more_messages_pb2 |
| 55 from google.protobuf import descriptor | 56 from google.protobuf import descriptor |
| 56 from google.protobuf import descriptor_database | 57 from google.protobuf import descriptor_database |
| 57 from google.protobuf import descriptor_pool | 58 from google.protobuf import descriptor_pool |
| 58 from google.protobuf import message_factory | 59 from google.protobuf import message_factory |
| 59 from google.protobuf import symbol_database | 60 from google.protobuf import symbol_database |
| 60 | 61 |
| 61 | 62 |
| 62 class DescriptorPoolTest(unittest.TestCase): | 63 class DescriptorPoolTest(unittest.TestCase): |
| 63 | 64 |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 pool = descriptor_pool.DescriptorPool() | 624 pool = descriptor_pool.DescriptorPool() |
| 624 file_desc = descriptor_pb2.FileDescriptorProto( | 625 file_desc = descriptor_pb2.FileDescriptorProto( |
| 625 name='some/file.proto', package='package') | 626 name='some/file.proto', package='package') |
| 626 file_desc.message_type.add(name='Message') | 627 file_desc.message_type.add(name='Message') |
| 627 pool.Add(file_desc) | 628 pool.Add(file_desc) |
| 628 self.assertEqual(pool.FindFileByName('some/file.proto').name, | 629 self.assertEqual(pool.FindFileByName('some/file.proto').name, |
| 629 'some/file.proto') | 630 'some/file.proto') |
| 630 self.assertEqual(pool.FindMessageTypeByName('package.Message').name, | 631 self.assertEqual(pool.FindMessageTypeByName('package.Message').name, |
| 631 'Message') | 632 'Message') |
| 632 | 633 |
| 634 def testFileDescriptorOptionsWithCustomDescriptorPool(self): |
| 635 # Create a descriptor pool, and add a new FileDescriptorProto to it. |
| 636 pool = descriptor_pool.DescriptorPool() |
| 637 file_name = 'file_descriptor_options_with_custom_descriptor_pool.proto' |
| 638 file_descriptor_proto = descriptor_pb2.FileDescriptorProto(name=file_name) |
| 639 extension_id = file_options_test_pb2.foo_options |
| 640 file_descriptor_proto.options.Extensions[extension_id].foo_name = 'foo' |
| 641 pool.Add(file_descriptor_proto) |
| 642 # The options set on the FileDescriptorProto should be available in the |
| 643 # descriptor even if they contain extensions that cannot be deserialized |
| 644 # using the pool. |
| 645 file_descriptor = pool.FindFileByName(file_name) |
| 646 options = file_descriptor.GetOptions() |
| 647 self.assertEqual('foo', options.Extensions[extension_id].foo_name) |
| 648 # The object returned by GetOptions() is cached. |
| 649 self.assertIs(options, file_descriptor.GetOptions()) |
| 650 |
| 633 | 651 |
| 634 @unittest.skipIf( | 652 @unittest.skipIf( |
| 635 api_implementation.Type() != 'cpp', | 653 api_implementation.Type() != 'cpp', |
| 636 'default_pool is only supported by the C++ implementation') | 654 'default_pool is only supported by the C++ implementation') |
| 637 class DefaultPoolTest(unittest.TestCase): | 655 class DefaultPoolTest(unittest.TestCase): |
| 638 | 656 |
| 639 def testFindMethods(self): | 657 def testFindMethods(self): |
| 640 # pylint: disable=g-import-not-at-top | 658 # pylint: disable=g-import-not-at-top |
| 641 from google.protobuf.pyext import _message | 659 from google.protobuf.pyext import _message |
| 642 pool = _message.default_pool | 660 pool = _message.default_pool |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 ExtensionField(1001, 'DescriptorPoolTest1')), | 759 ExtensionField(1001, 'DescriptorPoolTest1')), |
| 742 ]), | 760 ]), |
| 743 }, | 761 }, |
| 744 dependencies=['google/protobuf/internal/descriptor_pool_test1.proto', | 762 dependencies=['google/protobuf/internal/descriptor_pool_test1.proto', |
| 745 'google/protobuf/internal/more_messages.proto'], | 763 'google/protobuf/internal/more_messages.proto'], |
| 746 public_dependencies=['google/protobuf/internal/more_messages.proto']) | 764 public_dependencies=['google/protobuf/internal/more_messages.proto']) |
| 747 | 765 |
| 748 | 766 |
| 749 if __name__ == '__main__': | 767 if __name__ == '__main__': |
| 750 unittest.main() | 768 unittest.main() |
| OLD | NEW |