diff options
Diffstat (limited to 'python/google/protobuf/internal/descriptor_database_test.py')
-rw-r--r-- | python/google/protobuf/internal/descriptor_database_test.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/python/google/protobuf/internal/descriptor_database_test.py b/python/google/protobuf/internal/descriptor_database_test.py index 1f1a3db9..f97477b3 100644 --- a/python/google/protobuf/internal/descriptor_database_test.py +++ b/python/google/protobuf/internal/descriptor_database_test.py @@ -38,6 +38,7 @@ try: import unittest2 as unittest #PY26 except ImportError: import unittest +import warnings from google.protobuf import unittest_pb2 from google.protobuf import descriptor_pb2 @@ -98,6 +99,26 @@ class DescriptorDatabaseTest(unittest.TestCase): db.FindFileContainingSymbol, 'protobuf_unittest.NoneMessage') + def testConflictRegister(self): + db = descriptor_database.DescriptorDatabase() + unittest_fd = descriptor_pb2.FileDescriptorProto.FromString( + unittest_pb2.DESCRIPTOR.serialized_pb) + db.Add(unittest_fd) + conflict_fd = descriptor_pb2.FileDescriptorProto.FromString( + unittest_pb2.DESCRIPTOR.serialized_pb) + conflict_fd.name = 'other_file' + with warnings.catch_warnings(record=True) as w: + # Cause all warnings to always be triggered. + warnings.simplefilter('always') + db.Add(conflict_fd) + self.assertTrue(len(w)) + self.assertIs(w[0].category, RuntimeWarning) + self.assertIn('Conflict register for file "other_file": ', + str(w[0].message)) + self.assertIn('already defined in file ' + '"google/protobuf/unittest.proto"', + str(w[0].message)) + if __name__ == '__main__': unittest.main() |