Utilize assertIsInstance

Using assertTrue and the 'isinstance' function to test
if an object is in an instance of some class is too python2.4.
Our unit testing framework supports assertIsInstance which was created
for these types of tests. Let's use assertIsInstance for these tests.

Change-Id: Ife6ee0d96bcfa448f746378a52d0102fd44a7a28
This commit is contained in:
Zhongyue Luo 2013-09-05 10:06:38 +08:00
parent 3346a1111b
commit d7796858f1
24 changed files with 100 additions and 104 deletions

View File

@ -27,8 +27,7 @@ class TestFaults(test.NoDBTestCase):
# Ensure the status_int is set correctly on faults.
fault = faults.Fault(webob.exc.HTTPBadRequest(
explanation='test'))
self.assertTrue(isinstance(fault.wrapped_exc,
webob.exc.HTTPBadRequest))
self.assertIsInstance(fault.wrapped_exc, webob.exc.HTTPBadRequest)
def test_fault_exception_status_int(self):
# Ensure the status_int is set correctly on faults.

View File

@ -335,7 +335,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
def test_limit_class(self):
# Test that middleware selected correct limiter class.
assert isinstance(self.app._limiter, MockLimiter)
self.assertIsInstance(self.app._limiter, MockLimiter)
def test_good_request(self):
# Test successful GET request through middleware.

View File

@ -340,7 +340,7 @@ class LimitMiddlewareTest(BaseLimitTestSuite):
def test_limit_class(self):
# Test that middleware selected correct limiter class.
assert isinstance(self.app._limiter, MockLimiter)
self.assertIsInstance(self.app._limiter, MockLimiter)
def test_good_request(self):
# Test successful GET request through middleware.

View File

@ -303,7 +303,7 @@ class CellsMessageClassesTestCase(test.TestCase):
self.assertEqual(2, call_info['kwargs']['arg2'])
# Verify we get a new object with what we expect.
obj = call_info['kwargs']['obj']
self.assertTrue(isinstance(obj, CellsMsgingTestObject))
self.assertIsInstance(obj, CellsMsgingTestObject)
self.assertNotEqual(id(test_obj), id(obj))
self.assertEqual(test_obj.test, obj.test)
@ -962,7 +962,7 @@ class CellsTargetedMethodsTestCase(test.TestCase):
response = self.src_msg_runner.task_log_get_all(self.ctxt,
self.tgt_cell_name, task_name, begin, end, host=host,
state=state)
self.assertTrue(isinstance(response, list))
self.assertIsInstance(response, list)
self.assertEqual(1, len(response))
result = response[0].value_or_raise()
self.assertEqual(['fake_result'], result)

View File

@ -56,8 +56,9 @@ class CellsAPITestCase(test.NoDBTestCase):
self.assertEqual(self.fake_topic, call_info['topic'])
self.assertEqual(method, call_info['msg']['method'])
msg_version = call_info['msg']['version']
self.assertTrue(isinstance(msg_version, basestring),
"Message version %s is not a string" % msg_version)
self.assertIsInstance(msg_version, basestring,
msg="Message version %s is not a string" %
msg_version)
self.assertEqual(version, call_info['msg']['version'])
self.assertEqual(args, call_info['msg']['args'])

View File

@ -1035,7 +1035,7 @@ class ComputeTestCase(BaseTestCase):
@compute_manager.object_compat
def test_fn(_self, context, instance):
self.assertTrue(isinstance(instance, instance_obj.Instance))
self.assertIsInstance(instance, instance_obj.Instance)
self.assertEqual(instance.uuid, db_inst['uuid'])
test_fn(None, self.context, instance=db_inst)

View File

@ -43,7 +43,7 @@ class FakeDriverSingleNodeTestCase(BaseTestCase):
def test_get_host_stats(self):
stats = self.driver.get_host_stats()
self.assertTrue(isinstance(stats, dict))
self.assertIsInstance(stats, dict)
self.assertEqual(stats['hypervisor_hostname'], 'xyz')
def test_get_available_resource(self):
@ -59,7 +59,7 @@ class FakeDriverMultiNodeTestCase(BaseTestCase):
def test_get_host_stats(self):
stats = self.driver.get_host_stats()
self.assertTrue(isinstance(stats, list))
self.assertIsInstance(stats, list)
self.assertEqual(len(stats), 2)
self.assertEqual(stats[0]['hypervisor_hostname'], 'aaa')
self.assertEqual(stats[1]['hypervisor_hostname'], 'bbb')

View File

@ -1209,24 +1209,22 @@ class ConductorLocalAPITestCase(ConductorAPITestCase):
class ConductorImportTest(test.TestCase):
def test_import_conductor_local(self):
self.flags(use_local=True, group='conductor')
self.assertTrue(isinstance(conductor.API(),
conductor_api.LocalAPI))
self.assertTrue(isinstance(conductor.ComputeTaskAPI(),
conductor_api.LocalComputeTaskAPI))
self.assertIsInstance(conductor.API(), conductor_api.LocalAPI)
self.assertIsInstance(conductor.ComputeTaskAPI(),
conductor_api.LocalComputeTaskAPI)
def test_import_conductor_rpc(self):
self.flags(use_local=False, group='conductor')
self.assertTrue(isinstance(conductor.API(),
conductor_api.API))
self.assertTrue(isinstance(conductor.ComputeTaskAPI(),
conductor_api.ComputeTaskAPI))
self.assertIsInstance(conductor.API(), conductor_api.API)
self.assertIsInstance(conductor.ComputeTaskAPI(),
conductor_api.ComputeTaskAPI)
def test_import_conductor_override_to_local(self):
self.flags(use_local=False, group='conductor')
self.assertTrue(isinstance(conductor.API(use_local=True),
conductor_api.LocalAPI))
self.assertTrue(isinstance(conductor.ComputeTaskAPI(use_local=True),
conductor_api.LocalComputeTaskAPI))
self.assertIsInstance(conductor.API(use_local=True),
conductor_api.LocalAPI)
self.assertIsInstance(conductor.ComputeTaskAPI(use_local=True),
conductor_api.LocalComputeTaskAPI)
class ConductorPolicyTest(test.TestCase):

View File

@ -1840,11 +1840,11 @@ class InstanceTestCase(test.TestCase, ModelsObjectComparatorMixin):
self.ctxt, instance['uuid'],
{'access_ip_v4': netaddr.IPAddress('1.2.3.4'),
'access_ip_v6': netaddr.IPAddress('::1')})
self.assertTrue(isinstance(instance['access_ip_v4'], basestring))
self.assertTrue(isinstance(instance['access_ip_v6'], basestring))
self.assertIsInstance(instance['access_ip_v4'], basestring)
self.assertIsInstance(instance['access_ip_v6'], basestring)
instance = db.instance_get_by_uuid(self.ctxt, instance['uuid'])
self.assertTrue(isinstance(instance['access_ip_v4'], basestring))
self.assertTrue(isinstance(instance['access_ip_v6'], basestring))
self.assertIsInstance(instance['access_ip_v4'], basestring)
self.assertIsInstance(instance['access_ip_v6'], basestring)
class InstanceMetadataTestCase(test.TestCase):

View File

@ -433,7 +433,7 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
utils.change_deleted_column_type_to_id_type(engine, table_name)
table = utils.get_table(engine, table_name)
self.assertTrue(isinstance(table.c.deleted.type, Integer))
self.assertIsInstance(table.c.deleted.type, Integer)
def test_change_deleted_column_type_to_id_type_string(self):
table_name = 'abc'
@ -447,7 +447,7 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
utils.change_deleted_column_type_to_id_type(engine, table_name)
table = utils.get_table(engine, table_name)
self.assertTrue(isinstance(table.c.deleted.type, String))
self.assertIsInstance(table.c.deleted.type, String)
def test_change_deleted_column_type_to_id_type_custom(self):
table_name = 'abc'
@ -471,8 +471,8 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
table = utils.get_table(engine, table_name)
# NOTE(boris-42): There is no way to check has foo type CustomType.
# but sqlalchemy will set it to NullType.
self.assertTrue(isinstance(table.c.foo.type, NullType))
self.assertTrue(isinstance(table.c.deleted.type, Integer))
self.assertIsInstance(table.c.foo.type, NullType)
self.assertIsInstance(table.c.deleted.type, Integer)
def test_change_deleted_column_type_to_boolean(self):
table_name = 'abc'
@ -488,7 +488,7 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
table = utils.get_table(engine, table_name)
expected_type = Boolean if key != "mysql" else mysql.TINYINT
self.assertTrue(isinstance(table.c.deleted.type, expected_type))
self.assertIsInstance(table.c.deleted.type, expected_type)
def test_change_deleted_column_type_to_boolean_type_custom(self):
table_name = 'abc'
@ -512,8 +512,8 @@ class TestMigrationUtils(test_migrations.BaseMigrationTestCase):
table = utils.get_table(engine, table_name)
# NOTE(boris-42): There is no way to check has foo type CustomType.
# but sqlalchemy will set it to NullType.
self.assertTrue(isinstance(table.c.foo.type, NullType))
self.assertTrue(isinstance(table.c.deleted.type, Boolean))
self.assertIsInstance(table.c.foo.type, NullType)
self.assertIsInstance(table.c.deleted.type, Boolean)
def test_drop_unique_constraint_in_sqlite_fk_recreate(self):
engine = self.engines['sqlite']

View File

@ -771,10 +771,8 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
def _check_151(self, engine, data):
task_log = db_utils.get_table(engine, 'task_log')
row = task_log.select(task_log.c.id == data['id']).execute().first()
self.assertTrue(isinstance(row['period_beginning'],
datetime.datetime))
self.assertTrue(isinstance(row['period_ending'],
datetime.datetime))
self.assertIsInstance(row['period_beginning'], datetime.datetime)
self.assertIsInstance(row['period_ending'], datetime.datetime)
self.assertEqual(
data['period_beginning'], str(row['period_beginning']))
self.assertEqual(data['period_ending'], str(row['period_ending']))
@ -957,8 +955,8 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
# NullType needs a special case. We end up with NullType on sqlite
# where bigint is not defined.
if isinstance(base_column.type, sqlalchemy.types.NullType):
self.assertTrue(isinstance(shadow_column.type,
sqlalchemy.types.NullType))
self.assertIsInstance(shadow_column.type,
sqlalchemy.types.NullType)
else:
# Identical types do not test equal because sqlalchemy does not
# override __eq__, but if we stringify them then they do.
@ -1175,16 +1173,14 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
# These should not have their values changed, but should
# have corrected created_at stamps
self.assertEqual(result['value'], original['value'])
self.assertTrue(isinstance(result['created_at'],
datetime.datetime))
self.assertIsInstance(result['created_at'], datetime.datetime)
elif key.startswith('instance_type'):
# Values like instance_type_% should be stamped and values
# converted from 'None' to None where appropriate
self.assertEqual(result['value'],
None if original['value'] == 'None'
else original['value'])
self.assertTrue(isinstance(result['created_at'],
datetime.datetime))
self.assertIsInstance(result['created_at'], datetime.datetime)
else:
# None of the non-instance_type values should have
# been touched. Since we didn't set created_at on any
@ -2743,13 +2739,13 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
compute_nodes = db_utils.get_table(engine, 'compute_nodes')
if engine.name == "postgresql":
self.assertTrue(isinstance(compute_nodes.c.host_ip.type,
sqlalchemy.dialects.postgresql.INET))
self.assertIsInstance(compute_nodes.c.host_ip.type,
sqlalchemy.dialects.postgresql.INET)
else:
self.assertTrue(isinstance(compute_nodes.c.host_ip.type,
sqlalchemy.types.String))
self.assertTrue(isinstance(compute_nodes.c.supported_instances.type,
sqlalchemy.types.Text))
self.assertIsInstance(compute_nodes.c.host_ip.type,
sqlalchemy.types.String)
self.assertIsInstance(compute_nodes.c.supported_instances.type,
sqlalchemy.types.Text)
def _post_downgrade_208(self, engine):
self.assertColumnNotExists(engine, 'compute_nodes', 'host_ip')
@ -2966,8 +2962,7 @@ class TestNovaMigrations(BaseMigrationTestCase, CommonTestsMixIn):
self.assertColumnExists(engine, 'compute_nodes', 'pci_stats')
nodes = db_utils.get_table(engine, 'compute_nodes')
self.assertTrue(isinstance(nodes.c.pci_stats.type,
sqlalchemy.types.Text))
self.assertIsInstance(nodes.c.pci_stats.type, sqlalchemy.types.Text)
def _post_downgrade_213(self, engine):
self._213(engine)

View File

@ -43,8 +43,8 @@ class FakeImageServiceTestCase(test.NoDBTestCase):
'status', 'is_public', 'properties',
'disk_format', 'container_format',
'size']))
self.assertTrue(isinstance(image['created_at'], datetime.datetime))
self.assertTrue(isinstance(image['updated_at'], datetime.datetime))
self.assertIsInstance(image['created_at'], datetime.datetime)
self.assertIsInstance(image['updated_at'], datetime.datetime)
if not (isinstance(image['deleted_at'], datetime.datetime) or
image['deleted_at'] is None):

View File

@ -73,8 +73,7 @@ class _TestInstanceObject(object):
'nova_object.changes': ['uuid', 'launched_at']}
self.assertEqual(primitive, expected)
inst2 = instance.Instance.obj_from_primitive(primitive)
self.assertTrue(isinstance(inst2.launched_at,
datetime.datetime))
self.assertIsInstance(inst2.launched_at, datetime.datetime)
self.assertEqual(inst2.launched_at, red_letter_date)
def test_ip_deserialization(self):
@ -94,8 +93,8 @@ class _TestInstanceObject(object):
'access_ip_v4']}
self.assertEqual(primitive, expected)
inst2 = instance.Instance.obj_from_primitive(primitive)
self.assertTrue(isinstance(inst2.access_ip_v4, netaddr.IPAddress))
self.assertTrue(isinstance(inst2.access_ip_v6, netaddr.IPAddress))
self.assertIsInstance(inst2.access_ip_v4, netaddr.IPAddress)
self.assertIsInstance(inst2.access_ip_v6, netaddr.IPAddress)
self.assertEqual(inst2.access_ip_v4, netaddr.IPAddress('1.2.3.4'))
self.assertEqual(inst2.access_ip_v6, netaddr.IPAddress('::1'))
@ -458,8 +457,8 @@ class _TestInstanceObject(object):
for key in group:
self.assertEqual(group[key],
inst.security_groups[index][key])
self.assertTrue(isinstance(inst.security_groups[index],
security_group.SecurityGroup))
self.assertIsInstance(inst.security_groups[index],
security_group.SecurityGroup)
self.assertEqual(inst.security_groups.obj_what_changed(), set())
inst.security_groups[0].description = 'changed'
inst.save()
@ -733,8 +732,7 @@ class _TestInstanceListObject(object):
expected_attrs=['metadata'])
for i in range(0, len(fakes)):
self.assertTrue(isinstance(inst_list.objects[i],
instance.Instance))
self.assertIsInstance(inst_list.objects[i], instance.Instance)
self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid'])
self.assertRemotes()
@ -755,7 +753,7 @@ class _TestInstanceListObject(object):
expected_attrs=['metadata'])
self.assertEqual(1, len(inst_list))
self.assertTrue(isinstance(inst_list.objects[0], instance.Instance))
self.assertIsInstance(inst_list.objects[0], instance.Instance)
self.assertEqual(inst_list.objects[0].uuid, fakes[1]['uuid'])
self.assertRemotes()
@ -768,8 +766,7 @@ class _TestInstanceListObject(object):
self.mox.ReplayAll()
inst_list = instance.InstanceList.get_by_host(self.context, 'foo')
for i in range(0, len(fakes)):
self.assertTrue(isinstance(inst_list.objects[i],
instance.Instance))
self.assertIsInstance(inst_list.objects[i], instance.Instance)
self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid'])
self.assertEqual(inst_list.objects[i]._context, self.context)
self.assertEqual(inst_list.obj_what_changed(), set())
@ -785,8 +782,7 @@ class _TestInstanceListObject(object):
inst_list = instance.InstanceList.get_by_host_and_node(self.context,
'foo', 'bar')
for i in range(0, len(fakes)):
self.assertTrue(isinstance(inst_list.objects[i],
instance.Instance))
self.assertIsInstance(inst_list.objects[i], instance.Instance)
self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid'])
self.assertRemotes()
@ -801,8 +797,7 @@ class _TestInstanceListObject(object):
inst_list = instance.InstanceList.get_by_host_and_not_type(
self.context, 'foo', 'bar')
for i in range(0, len(fakes)):
self.assertTrue(isinstance(inst_list.objects[i],
instance.Instance))
self.assertIsInstance(inst_list.objects[i], instance.Instance)
self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid'])
self.assertRemotes()
@ -817,8 +812,7 @@ class _TestInstanceListObject(object):
inst_list = instance.InstanceList.get_hung_in_rebooting(self.context,
dt)
for i in range(0, len(fakes)):
self.assertTrue(isinstance(inst_list.objects[i],
instance.Instance))
self.assertIsInstance(inst_list.objects[i], instance.Instance)
self.assertEqual(inst_list.objects[i].uuid, fakes[i]['uuid'])
self.assertRemotes()

View File

@ -192,8 +192,8 @@ class _TestInstanceGroupObjects(test.TestCase):
self.assertEqual(len(groups), len(inst_list.objects))
self.assertEqual(len(groups), 4)
for i in range(0, len(groups)):
self.assertTrue(isinstance(inst_list.objects[i],
instance_group.InstanceGroup))
self.assertIsInstance(inst_list.objects[i],
instance_group.InstanceGroup)
self.assertEqual(inst_list.objects[i].uuid, groups[i]['uuid'])
def test_list_by_project_id(self):
@ -206,8 +206,8 @@ class _TestInstanceGroupObjects(test.TestCase):
self.assertEqual(len(groups), len(il.objects))
self.assertEqual(len(groups), 2)
for i in range(0, len(groups)):
self.assertTrue(isinstance(il.objects[i],
instance_group.InstanceGroup))
self.assertIsInstance(il.objects[i],
instance_group.InstanceGroup)
self.assertEqual(il.objects[i].uuid, groups[i]['uuid'])
self.assertEqual(il.objects[i].project_id, id)

View File

@ -17,6 +17,7 @@ import datetime
import iso8601
import netaddr
from testtools import matchers
from nova.conductor import rpcapi as conductor_rpcapi
from nova import context
@ -163,13 +164,13 @@ class TestUtils(test.TestCase):
self.assertEqual(utils.str_or_none('foo'), 'foo')
self.assertEqual(utils.str_or_none(1), '1')
self.assertEqual(utils.str_or_none(None), None)
self.assertTrue(isinstance(utils.str_or_none('foo'), unicode))
self.assertIsInstance(utils.str_or_none('foo'), unicode)
def test_str_value(self):
self.assertEqual('foo', utils.str_value('foo'))
self.assertEqual('1', utils.str_value(1))
self.assertRaises(ValueError, utils.str_value, None)
self.assertTrue(isinstance(utils.str_value('foo'), unicode))
self.assertIsInstance(utils.str_value('foo'), unicode)
def test_cstring(self):
self.assertEqual('foo', utils.cstring('foo'))
@ -308,6 +309,17 @@ class _BaseTestCase(test.TestCase):
def compare_obj(self, obj, db_obj, subs=None, allow_missing=None):
compare_obj(self, obj, db_obj, subs=subs, allow_missing=allow_missing)
def assertNotIsInstance(self, obj, cls, msg=None):
"""Python < v2.7 compatibility. Assert 'not isinstance(obj, cls)."""
try:
f = super(_BaseTestCase, self).assertNotIsInstance
except AttributeError:
self.assertThat(obj,
matchers.Not(matchers.IsInstance(cls)),
message=msg or '')
else:
f(obj, cls, msg=msg)
class _LocalTest(_BaseTestCase):
def setUp(self):
@ -701,7 +713,7 @@ class TestObjectSerializer(_BaseTestCase):
primitive = ser.serialize_entity(self.context, obj)
self.assertTrue('nova_object.name' in primitive)
obj2 = ser.deserialize_entity(self.context, primitive)
self.assertTrue(isinstance(obj2, MyObj))
self.assertIsInstance(obj2, MyObj)
self.assertEqual(self.context, obj2._context)
def test_object_serialization_iterables(self):
@ -712,8 +724,8 @@ class TestObjectSerializer(_BaseTestCase):
primitive = ser.serialize_entity(self.context, thing)
self.assertEqual(1, len(primitive))
for item in primitive:
self.assertFalse(isinstance(item, base.NovaObject))
self.assertNotIsInstance(item, base.NovaObject)
thing2 = ser.deserialize_entity(self.context, primitive)
self.assertEqual(1, len(thing2))
for item in thing2:
self.assertTrue(isinstance(item, MyObj))
self.assertIsInstance(item, MyObj)

View File

@ -304,7 +304,7 @@ class _TestPciDeviceListObject(object):
self.mox.ReplayAll()
devs = pci_device.PciDeviceList.get_by_compute_node(ctxt, 1)
for i in range(len(fake_pci_devs)):
self.assertTrue(isinstance(devs[i], pci_device.PciDevice))
self.assertIsInstance(devs[i], pci_device.PciDevice)
self.assertEqual(fake_pci_devs[i]['vendor_id'], devs[i].vendor_id)
self.assertRemotes()
@ -321,7 +321,7 @@ class _TestPciDeviceListObject(object):
devs = pci_device.PciDeviceList.get_by_instance_uuid(ctxt, '1')
self.assertEqual(len(devs), 2)
for i in range(len(fake_pci_devs)):
self.assertTrue(isinstance(devs[i], pci_device.PciDevice))
self.assertIsInstance(devs[i], pci_device.PciDevice)
self.assertEqual(devs[0].vendor_id, 'v')
self.assertEqual(devs[1].vendor_id, 'v')
self.assertRemotes()

View File

@ -128,8 +128,8 @@ class _TestSecurityGroupListObject(object):
self.mox.ReplayAll()
secgroup_list = security_group.SecurityGroupList.get_all(self.context)
for i in range(len(fake_secgroups)):
self.assertTrue(isinstance(secgroup_list[i],
security_group.SecurityGroup))
self.assertIsInstance(secgroup_list[i],
security_group.SecurityGroup)
self.assertEqual(fake_secgroups[i]['id'],
secgroup_list[i]['id'])
self.assertEqual(secgroup_list[i]._context, self.context)
@ -143,8 +143,8 @@ class _TestSecurityGroupListObject(object):
secgroup_list = security_group.SecurityGroupList.get_by_project(
self.context, 'fake-project')
for i in range(len(fake_secgroups)):
self.assertTrue(isinstance(secgroup_list[i],
security_group.SecurityGroup))
self.assertIsInstance(secgroup_list[i],
security_group.SecurityGroup)
self.assertEqual(fake_secgroups[i]['id'],
secgroup_list[i]['id'])
@ -159,8 +159,8 @@ class _TestSecurityGroupListObject(object):
secgroup_list = security_group.SecurityGroupList.get_by_instance(
self.context, inst)
for i in range(len(fake_secgroups)):
self.assertTrue(isinstance(secgroup_list[i],
security_group.SecurityGroup))
self.assertIsInstance(secgroup_list[i],
security_group.SecurityGroup)
self.assertEqual(fake_secgroups[i]['id'],
secgroup_list[i]['id'])

View File

@ -70,7 +70,7 @@ class SchedulerManagerTestCase(test.NoDBTestCase):
def test_1_correct_init(self):
# Correct scheduler driver
manager = self.manager
self.assertTrue(isinstance(manager.driver, self.driver_cls))
self.assertIsInstance(manager.driver, self.driver_cls)
def test_update_service_capabilities(self):
service_name = 'fake_service'

View File

@ -496,7 +496,7 @@ class MetadataHandlerTestCase(test.TestCase):
def test_callable(self):
def verify(req, meta_data):
self.assertTrue(isinstance(meta_data, CallableMD))
self.assertIsInstance(meta_data, CallableMD)
return "foo"
class CallableMD(object):

View File

@ -420,14 +420,14 @@ class QuotaEngineTestCase(test.TestCase):
quota_obj = quota.QuotaEngine()
self.assertEqual(quota_obj._resources, {})
self.assertTrue(isinstance(quota_obj._driver, quota.DbQuotaDriver))
self.assertIsInstance(quota_obj._driver, quota.DbQuotaDriver)
def test_init_override_string(self):
quota_obj = quota.QuotaEngine(
quota_driver_class='nova.tests.test_quota.FakeDriver')
self.assertEqual(quota_obj._resources, {})
self.assertTrue(isinstance(quota_obj._driver, FakeDriver))
self.assertIsInstance(quota_obj._driver, FakeDriver)
def test_init_override_obj(self):
quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver)

View File

@ -64,14 +64,11 @@ class BareMetalDriverNoDBTestCase(test.NoDBTestCase):
self.driver = bm_driver.BareMetalDriver(None)
def test_validate_driver_loading(self):
self.assertTrue(isinstance(self.driver.driver,
fake.FakeDriver))
self.assertTrue(isinstance(self.driver.vif_driver,
fake.FakeVifDriver))
self.assertTrue(isinstance(self.driver.volume_driver,
fake.FakeVolumeDriver))
self.assertTrue(isinstance(self.driver.firewall_driver,
fake.FakeFirewallDriver))
self.assertIsInstance(self.driver.driver, fake.FakeDriver)
self.assertIsInstance(self.driver.vif_driver, fake.FakeVifDriver)
self.assertIsInstance(self.driver.volume_driver, fake.FakeVolumeDriver)
self.assertIsInstance(self.driver.firewall_driver,
fake.FakeFirewallDriver)
class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
@ -137,7 +134,7 @@ class BareMetalDriverWithDBTestCase(bm_db_base.BMDBTestCase):
def test_get_host_stats(self):
node = self._create_node()
stats = self.driver.get_host_stats()
self.assertTrue(isinstance(stats, list))
self.assertIsInstance(stats, list)
self.assertEqual(len(stats), 1)
stats = stats[0]
self.assertEqual(stats['cpu_arch'], 'test')

View File

@ -644,7 +644,7 @@ class BackendTestCase(test.NoDBTestCase):
failure = ('Expected %s,' +
' but got %s.') % (class_object.__name__,
instance.__class__.__name__)
self.assertTrue(isinstance(instance, class_object), failure)
self.assertIsInstance(instance, class_object, msg=failure)
assertIsInstance(image1, image_not_cow)
assertIsInstance(image2, image_cow)

View File

@ -511,7 +511,7 @@ class _VirtDriverTestCase(_FakeDriverBackendTestCase):
fake_libvirt_utils.files['dummy.log'] = ''
instance_ref, network_info = self._get_running_instance()
console_output = self.connection.get_console_output(instance_ref)
self.assertTrue(isinstance(console_output, basestring))
self.assertIsInstance(console_output, basestring)
@catch_notimplementederror
def test_get_vnc_console(self):

View File

@ -548,7 +548,7 @@ class XenAPIVMTestCase(stubs.XenAPITestBase):
self.fake_upload_called = True
self.assertEqual(ctx, self.context)
self.assertEqual(inst, instance)
self.assertTrue(isinstance(vdi_uuids, list))
self.assertIsInstance(vdi_uuids, list)
self.assertEqual(img_id, image_id)
self.stubs.Set(glance.GlanceStore, 'upload_image',