Replace assert* with more suitable asserts in tests
The following replacements were done in unit tests to have clearer messages in case of failure: - assertTrue(a == b or a == c) with assertIn(a, [b, c]) - assertTrue(type(a) == dict) with assertIsInstance(a, dict) - assertTrue(type(a) == int) with assertIsInstance(a, int) Also assertTrue with several conditions was splitted. Change-Id: Id6e5db9ead8d8dceb9f416c1b55280855d25e604
This commit is contained in:
parent
7b1dada7fe
commit
fe1d1b6078
@ -815,8 +815,7 @@ class CinderCloudTestCase(test.TestCase):
|
||||
|
||||
self.assertEqual(len(vols), 2)
|
||||
for vol in vols:
|
||||
self.assertTrue(str(vol['id']) == str(vol1_uuid) or
|
||||
str(vol['id']) == str(vol2_uuid))
|
||||
self.assertIn(str(vol['id']), [str(vol1_uuid), str(vol2_uuid)])
|
||||
if str(vol['id']) == str(vol1_uuid):
|
||||
self.volume_api.attach(self.context, vol['id'],
|
||||
instance_uuid, '/dev/sdb')
|
||||
@ -847,10 +846,8 @@ class CinderCloudTestCase(test.TestCase):
|
||||
vols = [v for v in vols if v['instance_uuid'] == instance_uuid]
|
||||
self.assertEqual(len(vols), 2)
|
||||
for vol in vols:
|
||||
self.assertTrue(str(vol['id']) == str(vol1_uuid) or
|
||||
str(vol['id']) == str(vol2_uuid))
|
||||
self.assertTrue(vol['mountpoint'] == '/dev/sdb' or
|
||||
vol['mountpoint'] == '/dev/sdc')
|
||||
self.assertIn(str(vol['id']), [str(vol1_uuid), str(vol2_uuid)])
|
||||
self.assertIn(vol['mountpoint'], ['/dev/sdb', '/dev/sdc'])
|
||||
self.assertEqual(vol['instance_uuid'], instance_uuid)
|
||||
self.assertEqual(vol['status'], "in-use")
|
||||
self.assertEqual(vol['attach_status'], "attached")
|
||||
|
@ -853,9 +853,9 @@ class HyperVAPITestCase(HyperVAPIBaseTestCase):
|
||||
func_call_matcher.call)
|
||||
self._mox.VerifyAll()
|
||||
|
||||
self.assertTrue(self._image_metadata and
|
||||
"disk_format" in self._image_metadata and
|
||||
self._image_metadata["disk_format"] == "vhd")
|
||||
self.assertTrue(self._image_metadata)
|
||||
self.assertIn("disk_format", self._image_metadata)
|
||||
self.assertEqual("vhd", self._image_metadata["disk_format"])
|
||||
|
||||
# Assert states changed in correct order
|
||||
self.assertIsNone(func_call_matcher.match())
|
||||
|
@ -4020,7 +4020,7 @@ class LibvirtConnTestCase(test.TestCase):
|
||||
self.mox.ReplayAll()
|
||||
ret = conn.check_can_live_migrate_source(self.context, instance_ref,
|
||||
dest_check_data)
|
||||
self.assertTrue(type(ret) == dict)
|
||||
self.assertIsInstance(ret, dict)
|
||||
self.assertIn('is_shared_storage', ret)
|
||||
|
||||
def test_check_can_live_migrate_source_vol_backed_w_disk_raises(self):
|
||||
|
@ -276,7 +276,7 @@ class FakeLibvirtTests(test.NoDBTestCase):
|
||||
|
||||
def test_getVersion(self):
|
||||
conn = self.get_openAuth_curry_func()('qemu:///system')
|
||||
self.assertTrue(type(conn.getVersion()) is int)
|
||||
self.assertIsInstance(conn.getVersion(), int)
|
||||
|
||||
def test_getCapabilities(self):
|
||||
conn = self.get_openAuth_curry_func()('qemu:///system')
|
||||
|
Loading…
Reference in New Issue
Block a user