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 | |
43 from google.protobuf import symbol_database | 42 from google.protobuf import symbol_database |
44 | 43 |
45 | |
46 class SymbolDatabaseTest(unittest.TestCase): | 44 class SymbolDatabaseTest(unittest.TestCase): |
47 | 45 |
48 def _Database(self): | 46 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 # The C++ implementation does not allow mixing descriptors from | 50 return symbol_database.Default() |
51 # different pools. | |
52 db = symbol_database.SymbolDatabase(pool=descriptor_pool.Default()) | |
53 else: | 51 else: |
54 db = symbol_database.SymbolDatabase() | 52 db = symbol_database.SymbolDatabase() |
55 # Register representative types from unittest_pb2. | 53 # Register representative types from unittest_pb2. |
56 db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) | 54 db.RegisterFileDescriptor(unittest_pb2.DESCRIPTOR) |
57 db.RegisterMessage(unittest_pb2.TestAllTypes) | 55 db.RegisterMessage(unittest_pb2.TestAllTypes) |
58 db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) | 56 db.RegisterMessage(unittest_pb2.TestAllTypes.NestedMessage) |
59 db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) | 57 db.RegisterMessage(unittest_pb2.TestAllTypes.OptionalGroup) |
60 db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) | 58 db.RegisterMessage(unittest_pb2.TestAllTypes.RepeatedGroup) |
61 db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) | 59 db.RegisterEnumDescriptor(unittest_pb2.ForeignEnum.DESCRIPTOR) |
62 db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) | 60 db.RegisterEnumDescriptor(unittest_pb2.TestAllTypes.NestedEnum.DESCRIPTOR) |
63 return db | 61 return db |
64 | 62 |
65 def testGetPrototype(self): | 63 def testGetPrototype(self): |
66 instance = self._Database().GetPrototype( | 64 instance = self._Database().GetPrototype( |
67 unittest_pb2.TestAllTypes.DESCRIPTOR) | 65 unittest_pb2.TestAllTypes.DESCRIPTOR) |
68 self.assertTrue(instance is unittest_pb2.TestAllTypes) | 66 self.assertTrue(instance is unittest_pb2.TestAllTypes) |
69 | 67 |
70 def testGetMessages(self): | 68 def testGetMessages(self): |
71 messages = self._Database().GetMessages( | 69 messages = self._Database().GetMessages( |
72 ['google/protobuf/unittest.proto']) | 70 ['google/protobuf/unittest.proto']) |
73 self.assertTrue( | 71 self.assertTrue( |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 120 |
123 def testFindFileByName(self): | 121 def testFindFileByName(self): |
124 self.assertEqual( | 122 self.assertEqual( |
125 'google/protobuf/unittest.proto', | 123 'google/protobuf/unittest.proto', |
126 self._Database().pool.FindFileByName( | 124 self._Database().pool.FindFileByName( |
127 'google/protobuf/unittest.proto').name) | 125 'google/protobuf/unittest.proto').name) |
128 | 126 |
129 | 127 |
130 if __name__ == '__main__': | 128 if __name__ == '__main__': |
131 unittest.main() | 129 unittest.main() |
OLD | NEW |