Change assertTrue(isinstance()) by optimal assert

Some of tests use different method of assertTrue(isinstance(A, B)) or
assertEqual(type(A), B). The correct way is to use assertIsInstance(A,
B) provided by testtools.

Change-Id: I9053c9deaa71ee12e10db73b19250b3a32f3d93c
Closes-bug: #1268480
This commit is contained in:
Shuquan Huang 2015-12-31 16:14:44 +08:00
parent 0af7c9649b
commit 75e7b788a4
8 changed files with 19 additions and 21 deletions

View File

@ -328,7 +328,7 @@ class TestCase(base_test.BaseTestCase):
try: try:
f = super(TestCase, self).assertIsInstance f = super(TestCase, self).assertIsInstance
except AttributeError: except AttributeError:
self.assertTrue(isinstance(a, b)) self.assertIsInstance(a, b)
else: else:
f(a, b, *args, **kwargs) f(a, b, *args, **kwargs)

View File

@ -193,5 +193,5 @@ class SchedulerStatsTestCase(test.TestCase):
def test_create_resource(self): def test_create_resource(self):
result = scheduler_stats.create_resource() result = scheduler_stats.create_resource()
self.assertTrue(isinstance(result.controller, self.assertIsInstance(result.controller,
scheduler_stats.SchedulerStatsController)) scheduler_stats.SchedulerStatsController)

View File

@ -76,9 +76,9 @@ class AvailabilityZonesAPITest(test.TestCase):
assert_called_once_with(ctxt) assert_called_once_with(ctxt)
mock_policy_check.assert_called_once_with( mock_policy_check.assert_called_once_with(
ctxt, controller.resource_name, 'index') ctxt, controller.resource_name, 'index')
self.assertTrue(isinstance(result, dict)) self.assertIsInstance(result, dict)
self.assertEqual(["availability_zones"], list(result.keys())) self.assertEqual(["availability_zones"], list(result.keys()))
self.assertTrue(isinstance(result["availability_zones"], list)) self.assertIsInstance(result["availability_zones"], list)
self.assertEqual(2, len(result["availability_zones"])) self.assertEqual(2, len(result["availability_zones"]))
self.assertTrue(azs[0] in result["availability_zones"]) self.assertTrue(azs[0] in result["availability_zones"])
azs[1].pop("deleted") azs[1].pop("deleted")

View File

@ -243,7 +243,7 @@ class NovaApiTestCase(test.TestCase):
def test_fixed_ip_get(self): def test_fixed_ip_get(self):
fixed_ip = 'fake_fixed_ip' fixed_ip = 'fake_fixed_ip'
result = self.api.fixed_ip_get(self.ctx, fixed_ip) result = self.api.fixed_ip_get(self.ctx, fixed_ip)
self.assertTrue(isinstance(result, dict)) self.assertIsInstance(result, dict)
self.assertEqual(fixed_ip, result['address']) self.assertEqual(fixed_ip, result['address'])
def test_fixed_ip_reserve(self): def test_fixed_ip_reserve(self):
@ -259,7 +259,7 @@ class NovaApiTestCase(test.TestCase):
def test_network_get(self): def test_network_get(self):
net_id = 'fake_net_id' net_id = 'fake_net_id'
net = self.api.network_get(self.ctx, net_id) net = self.api.network_get(self.ctx, net_id)
self.assertTrue(isinstance(net, dict)) self.assertIsInstance(net, dict)
self.assertEqual(net_id, net['id']) self.assertEqual(net_id, net['id'])

View File

@ -248,7 +248,7 @@ class HostManagerTestCase(test.TestCase):
}, },
}, },
] ]
self.assertTrue(isinstance(res, list)) self.assertIsInstance(res, list)
self.assertEqual(len(expected), len(res)) self.assertEqual(len(expected), len(res))
for pool in expected: for pool in expected:
self.assertIn(pool, res) self.assertIn(pool, res)
@ -389,8 +389,8 @@ class HostManagerTestCase(test.TestCase):
}, },
}, },
] ]
self.assertTrue(isinstance(res, list)) self.assertIsInstance(res, list)
self.assertTrue(isinstance(self.host_manager.host_state_map, dict)) self.assertIsInstance(self.host_manager.host_state_map, dict)
self.assertEqual(len(expected), len(res)) self.assertEqual(len(expected), len(res))
for pool in expected: for pool in expected:
self.assertIn(pool, res) self.assertIn(pool, res)
@ -469,8 +469,8 @@ class HostManagerTestCase(test.TestCase):
}, },
}, },
] ]
self.assertTrue(isinstance(res, list)) self.assertIsInstance(res, list)
self.assertTrue(isinstance(self.host_manager.host_state_map, dict)) self.assertIsInstance(self.host_manager.host_state_map, dict)
self.assertEqual(len(expected), len(res)) self.assertEqual(len(expected), len(res))
self.assertEqual(len(expected), self.assertEqual(len(expected),
len(self.host_manager.host_state_map)) len(self.host_manager.host_state_map))

View File

@ -54,8 +54,7 @@ class SchedulerManagerTestCase(test.TestCase):
def test_1_correct_init(self): def test_1_correct_init(self):
# Correct scheduler driver # Correct scheduler driver
manager = self.manager manager = self.manager
self.assertTrue(isinstance(manager.driver, self.assertIsInstance(manager.driver, self.driver_cls)
self.driver_cls))
@ddt.data('manila.scheduler.filter_scheduler.FilterScheduler', @ddt.data('manila.scheduler.filter_scheduler.FilterScheduler',
'manila.scheduler.drivers.filter.FilterScheduler') 'manila.scheduler.drivers.filter.FilterScheduler')
@ -63,8 +62,7 @@ class SchedulerManagerTestCase(test.TestCase):
test_manager = manager.SchedulerManager(scheduler_driver=driver_class) test_manager = manager.SchedulerManager(scheduler_driver=driver_class)
self.assertTrue(isinstance(test_manager.driver, self.assertIsInstance(test_manager.driver, filter.FilterScheduler)
filter.FilterScheduler))
def test_init_host(self): def test_init_host(self):

View File

@ -257,14 +257,14 @@ class QuotaEngineTestCase(test.TestCase):
quota_obj = quota.QuotaEngine() quota_obj = quota.QuotaEngine()
self.assertEqual({}, quota_obj._resources) 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): def test_init_override_string(self):
quota_obj = quota.QuotaEngine( quota_obj = quota.QuotaEngine(
quota_driver_class='manila.tests.test_quota.FakeDriver') quota_driver_class='manila.tests.test_quota.FakeDriver')
self.assertEqual({}, quota_obj._resources) self.assertEqual({}, quota_obj._resources)
self.assertTrue(isinstance(quota_obj._driver, FakeDriver)) self.assertIsInstance(quota_obj._driver, FakeDriver)
def test_init_override_obj(self): def test_init_override_obj(self):
quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver) quota_obj = quota.QuotaEngine(quota_driver_class=FakeDriver)

View File

@ -196,7 +196,7 @@ class ShareServersAdminTest(base.BaseSharesAdminTest):
# share_network_name is not empty # share_network_name is not empty
self.assertTrue(len(server["share_network_name"]) > 0) self.assertTrue(len(server["share_network_name"]) > 0)
# backend_details should be a dict # backend_details should be a dict
self.assertTrue(isinstance(server["backend_details"], dict)) self.assertIsInstance(server["backend_details"], dict)
@test.attr(type=["gate", "smoke", ]) @test.attr(type=["gate", "smoke", ])
def test_show_share_server_details(self): def test_show_share_server_details(self):
@ -205,8 +205,8 @@ class ShareServersAdminTest(base.BaseSharesAdminTest):
servers[0]["id"]) servers[0]["id"])
# If details are present they and their values should be only strings # If details are present they and their values should be only strings
for k, v in details.iteritems(): for k, v in details.iteritems():
self.assertTrue(isinstance(k, six.string_types)) self.assertIsInstance(k, six.string_types)
self.assertTrue(isinstance(v, six.string_types)) self.assertIsInstance(v, six.string_types)
@test.attr(type=["gate", "smoke", ]) @test.attr(type=["gate", "smoke", ])
def _delete_share_server(self, delete_share_network): def _delete_share_server(self, delete_share_network):