| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 """Tests for google.protobuf.symbol_database.""" | 33 """Tests for google.protobuf.symbol_database.""" |
| 34 | 34 |
| 35 try: | 35 try: |
| 36 import unittest2 as unittest #PY26 | 36 import unittest2 as unittest #PY26 |
| 37 except ImportError: | 37 except ImportError: |
| 38 import unittest | 38 import unittest |
| 39 | 39 |
| 40 from google.protobuf import unittest_pb2 | 40 from google.protobuf import unittest_pb2 |
| 41 from google.protobuf import descriptor | 41 from google.protobuf import descriptor |
| 42 from google.protobuf import descriptor_pool |
| 42 from google.protobuf import symbol_database | 43 from google.protobuf import symbol_database |
| 43 | 44 |
| 45 |
| 44 class SymbolDatabaseTest(unittest.TestCase): | 46 class SymbolDatabaseTest(unittest.TestCase): |
| 45 | 47 |
| 46 def _Database(self): | 48 def _Database(self): |
| 47 # TODO(b/17734095): Remove this difference when the C++ implementation | |
| 48 # supports multiple databases. | |
| 49 if descriptor._USE_C_DESCRIPTORS: | 49 if descriptor._USE_C_DESCRIPTORS: |
| 50 return symbol_database.Default() | 50 # The C++ implementation does not allow mixing descriptors from |
| 51 # different pools. |
| 52 db = symbol_database.SymbolDatabase(pool=descriptor_pool.Default()) |
| 51 else: | 53 else: |
| 52 db = symbol_database.SymbolDatabase() | 54 db = symbol_database.SymbolDatabase() |
| 53 # Register representative types from unittest_pb2. | 55 # Register representative types from unittest_pb2. |
| 54 db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) | 56 db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) |
| 55 db.RegisterMessage(unittest_pb2.TestAllTypes) | 57 db.RegisterMessage(unittest_pb2.TestAllTypes) |
| 56 db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) | 58 db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) |
| 57 db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) | 59 db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) |
| 58 db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) | 60 db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) |
| 59 db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) | 61 db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) |
| 60 db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) | 62 db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) |
| 61 return db | 63 return db |
| 62 | 64 |
| 63 def testGetPrototype(self): | 65 def testGetPrototype(self): |
| 64 instance = self._Database().GetPrototype( | 66 instance = self._Database().GetPrototype( |
| 65 unittest_pb2.TestAllTypes.DESCRIPTOR) | 67 unittest_pb2.TestAllTypes.DESCRIPTOR) |
| 66 self.assertTrue(instance is unittest_pb2.TestAllTypes) | 68 self.assertTrue(instance is unittest_pb2.TestAllTypes) |
| 67 | 69 |
| 68 def testGetMessages(self): | 70 def testGetMessages(self): |
| 69 messages = self._Database().GetMessages( | 71 messages = self._Database().GetMessages( |
| 70 ['google/protobuf/unittest.proto']) | 72 ['google/protobuf/unittest.proto']) |
| 71 self.assertTrue( | 73 self.assertTrue( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 122 |
| 121 def testFindFileByName(self): | 123 def testFindFileByName(self): |
| 122 self.assertEqual( | 124 self.assertEqual( |
| 123 'google/protobuf/unittest.proto', | 125 'google/protobuf/unittest.proto', |
| 124 self._Database().pool.FindFileByName( | 126 self._Database().pool.FindFileByName( |
| 125 'google/protobuf/unittest.proto').name) | 127 'google/protobuf/unittest.proto').name) |
| 126 | 128 |
| 127 | 129 |
| 128 if __name__ == '__main__': | 130 if __name__ == '__main__': |
| 129 unittest.main() | 131 unittest.main() |
| OLD | NEW |