From 821fcb2ded668a688316b66fcd5ff28e868298e7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 12 Aug 2015 14:22:25 -0400 Subject: Use assertIsInstance --- python/google/protobuf/internal/message_test.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'python/google/protobuf/internal/message_test.py') diff --git a/python/google/protobuf/internal/message_test.py b/python/google/protobuf/internal/message_test.py index cf3fcfe9..c4c660ec 100755 --- a/python/google/protobuf/internal/message_test.py +++ b/python/google/protobuf/internal/message_test.py @@ -683,9 +683,7 @@ class MessageTest(unittest.TestCase): in the value being converted to a Unicode string.""" m = message_module.TestAllTypes() m.optional_string = str('') - self.assertTrue(isinstance(m.optional_string, six.text_type)) - -# TODO(haberman): why are these tests Google-internal only? + self.assertIsInstance(m.optional_string, six.text_type) def testLongValuedSlice(self, message_module): """It should be possible to use long-valued indicies in slices @@ -1071,14 +1069,13 @@ class Proto2Test(unittest.TestCase): repeated_nested_enum=['FOO', unittest_pb2.TestAllTypes.BAR], default_int32=800, oneof_string='y') - self.assertTrue(isinstance(message, unittest_pb2.TestAllTypes)) + self.assertIsInstance(message, unittest_pb2.TestAllTypes) self.assertEqual(100, message.optional_int32) self.assertEqual(200, message.optional_fixed32) self.assertEqual(300.5, message.optional_float) self.assertEqual(b'x', message.optional_bytes) self.assertEqual(400, message.optionalgroup.a) - self.assertTrue(isinstance(message.optional_nested_message, - unittest_pb2.TestAllTypes.NestedMessage)) + self.assertIsInstance(message.optional_nested_message, unittest_pb2.TestAllTypes.NestedMessage) self.assertEqual(500, message.optional_nested_message.bb) self.assertEqual(unittest_pb2.TestAllTypes.BAZ, message.optional_nested_enum) @@ -1236,7 +1233,7 @@ class Proto3Test(unittest.TestCase): self.assertTrue('abc' in msg.map_string_string) self.assertTrue(888 in msg.map_int32_enum) - self.assertTrue(isinstance(msg.map_string_string['abc'], six.text_type)) + self.assertIsInstance(msg.map_string_string['abc'], six.text_type) # Accessing an unset key still throws TypeError of the type of the key # is incorrect. @@ -1315,7 +1312,7 @@ class Proto3Test(unittest.TestCase): msg = map_unittest_pb2.TestMap() unicode_obj = u'\u1234' - bytes_obj = unicode_obj.encode('utf8') + bytes_obj = unicode_obj.encode('utf8') msg.map_string_string[bytes_obj] = bytes_obj @@ -1324,8 +1321,8 @@ class Proto3Test(unittest.TestCase): self.assertEqual(key, unicode_obj) self.assertEqual(value, unicode_obj) - self.assertTrue(isinstance(key, six.text_type)) - self.assertTrue(isinstance(value, six.text_type)) + self.assertIsInstance(key, six.text_type) + self.assertIsInstance(value, six.text_type) def testMessageMap(self): msg = map_unittest_pb2.TestMap() @@ -1493,7 +1490,7 @@ class Proto3Test(unittest.TestCase): submsg = msg.map_int32_foreign_message[111] self.assertIs(submsg, msg.map_int32_foreign_message[111]) - self.assertTrue(isinstance(submsg, unittest_pb2.ForeignMessage)) + self.assertIsInstance(submsg, unittest_pb2.ForeignMessage) submsg.c = 5 -- cgit v1.2.3