Replace assertTrue with explicit assertIsInstance

assertIsInstance can provide useful message when test fails,
this patch replaces assertTrue(isinstance(x, y)) with
assertIsInstance(x, y).

Change-Id: Ia87b6b8d15f96ce7cf4082fc5ec599ade1d8114e
Closes-Bug: #1268480
This commit is contained in:
ZhiQiang Fan 2014-01-17 18:30:11 +08:00 committed by ZhiQiang Fan
parent dde3e6f615
commit f1c1e3ef17
3 changed files with 20 additions and 22 deletions

View File

@ -575,8 +575,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
'created_at': 'DateTime', 'updated_at': 'DateTime'
}
for col, coltype in nodes_col.items():
self.assertTrue(isinstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype)))
self.assertIsInstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype))
ifaces = db_utils.get_table(engine, 'ifaces')
ifaces_col = {
@ -584,8 +584,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
'extra': 'Text', 'created_at': 'DateTime', 'updated_at': 'DateTime'
}
for col, coltype in ifaces_col.items():
self.assertTrue(isinstance(ifaces.c[col].type,
getattr(sqlalchemy.types, coltype)))
self.assertIsInstance(ifaces.c[col].type,
getattr(sqlalchemy.types, coltype))
fkey, = ifaces.c.node_id.foreign_keys
self.assertEqual(nodes.c.id.name, fkey.column.name)
@ -600,8 +600,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
'deploy_info': 'Text', 'reservation': 'String'
}
for col, coltype in new_col.items():
self.assertTrue(isinstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype)))
self.assertIsInstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype))
deleted_cols = ['power_info', 'cpu_arch', 'cpu_num', 'memory',
'local_storage_max', 'image_path', 'instance_name']
@ -610,10 +610,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
def _check_003(self, engine, data):
chassis = db_utils.get_table(engine, 'chassis')
self.assertTrue(isinstance(chassis.c.id.type,
sqlalchemy.types.Integer))
self.assertTrue(isinstance(chassis.c.uuid.type,
sqlalchemy.types.String))
self.assertIsInstance(chassis.c.id.type, sqlalchemy.types.Integer)
self.assertIsInstance(chassis.c.uuid.type, sqlalchemy.types.String)
def _check_004(self, engine, data):
self.assertTrue(engine.dialect.has_table(engine.connect(), 'ports'))
@ -629,7 +627,7 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
def _check_006(self, engine, data):
ports = db_utils.get_table(engine, 'ports')
self.assertTrue(isinstance(ports.c.uuid.type, sqlalchemy.types.String))
self.assertIsInstance(ports.c.uuid.type, sqlalchemy.types.String)
nodes = db_utils.get_table(engine, 'nodes')
nodes_data = {
@ -655,13 +653,13 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
new_col = {'extra': 'Text', 'created_at': 'DateTime',
'updated_at': 'DateTime'}
for col, coltype in new_col.items():
self.assertTrue(isinstance(chassis.c[col].type,
getattr(sqlalchemy.types, coltype)))
self.assertIsInstance(chassis.c[col].type,
getattr(sqlalchemy.types, coltype))
def _check_008(self, engine, data):
chassis = db_utils.get_table(engine, 'chassis')
self.assertTrue(isinstance(chassis.c.description.type,
sqlalchemy.types.String))
self.assertIsInstance(chassis.c.description.type,
sqlalchemy.types.String)
def _check_009(self, engine, data):
nodes = db_utils.get_table(engine, 'nodes')
@ -675,8 +673,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
'provision_state': 'String',
'target_provision_state': 'String'}
for col, coltype in new_col.items():
self.assertTrue(isinstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype)))
self.assertIsInstance(nodes.c[col].type,
getattr(sqlalchemy.types, coltype))
def _check_010(self, engine, data):
insp = sqlalchemy.engine.reflection.Inspector.from_engine(engine)
@ -734,8 +732,8 @@ class TestMigrations(BaseMigrationTestCase, WalkVersionsMixin):
# only added one 'last_error' column
self.assertEqual(len(col_names_pre), len(col_names) - 1)
self.assertTrue(isinstance(nodes.c['last_error'].type,
getattr(sqlalchemy.types, 'Text')))
self.assertIsInstance(nodes.c['last_error'].type,
getattr(sqlalchemy.types, 'Text'))
def _check_014(self, engine, data):
if engine.name == 'sqlite':

View File

@ -500,7 +500,7 @@ class TestObjectSerializer(test_base.TestCase):
primitive = ser.serialize_entity(ctxt, obj)
self.assertTrue('ironic_object.name' in primitive)
obj2 = ser.deserialize_entity(ctxt, primitive)
self.assertTrue(isinstance(obj2, MyObj))
self.assertIsInstance(obj2, MyObj)
self.assertEqual(ctxt, obj2._context)
def test_object_serialization_iterables(self):
@ -516,4 +516,4 @@ class TestObjectSerializer(test_base.TestCase):
thing2 = ser.deserialize_entity(ctxt, primitive)
self.assertEqual(1, len(thing2))
for item in thing2:
self.assertTrue(isinstance(item, MyObj))
self.assertIsInstance(item, MyObj)

View File

@ -390,7 +390,7 @@ class UUIDTestCase(base.TestCase):
def test_generate_uuid(self):
uuid_string = utils.generate_uuid()
self.assertTrue(isinstance(uuid_string, str))
self.assertIsInstance(uuid_string, str)
self.assertEqual(len(uuid_string), 36)
# make sure there are 4 dashes
self.assertEqual(len(uuid_string.replace('-', '')), 32)