Use more specific asserts in tests

I changed asserts with more specific assert methods.
e.g.: from assertTrue(sth == None) to assertIsNone(*) or
assertTrue(isinstance(inst, type)) to assertIsInstace(inst, type) or
assertTrue(not sth) to assertFalse(sth).

The code gets more readable, and a better description will be shown on fail.

Change-Id: I8be876e0d2a1ea5d6f8454ca973e2d874d10283d
This commit is contained in:
Gábor Antal 2016-09-05 16:08:04 +02:00
parent 57c397d822
commit ce184797f0
4 changed files with 11 additions and 11 deletions

View File

@ -85,12 +85,12 @@ class APIVersionTestCase(utils.TestCase):
v4 = api_versions.APIVersion("2.0")
v_null = api_versions.APIVersion()
self.assertTrue(v1 < v2)
self.assertTrue(v3 > v2)
self.assertTrue(v1 != v2)
self.assertTrue(v1 == v4)
self.assertTrue(v1 != v_null)
self.assertTrue(v_null == v_null)
self.assertTrue(v1.__lt__(v2))
self.assertTrue(v3.__gt__(v2))
self.assertTrue(v1.__ne__(v2))
self.assertTrue(v1.__eq__(v4))
self.assertTrue(v1.__ne__(v_null))
self.assertTrue(v_null.__eq__(v_null))
self.assertRaises(TypeError, v1.__le__, "2.1")
def test_version_matches(self):

View File

@ -173,7 +173,7 @@ class DeprecatedActionTest(utils.TestCase):
self.assertEqual(result.emitted, set())
self.assertIsNone(result.use)
self.assertEqual(result.real_action_args, False)
self.assertIs(result.real_action_args, False)
self.assertIsNone(result.real_action)
mock_init.assert_called_once_with(
'option_strings', 'dest', help='Deprecated', a=1, b=2, c=3)
@ -200,7 +200,7 @@ class DeprecatedActionTest(utils.TestCase):
self.assertEqual(result.emitted, set())
self.assertIsNone(result.use)
self.assertEqual(result.real_action_args, False)
self.assertIs(result.real_action_args, False)
self.assertEqual(result.real_action, action.return_value)
mock_init.assert_called_once_with(
'option_strings', 'dest', help='Deprecated', a=1, b=2, c=3)

View File

@ -35,7 +35,7 @@ class TenantNetworkExtensionTests(utils.TestCase):
nets = self.cs.tenant_networks.list()
self.assert_request_id(nets, fakes.FAKE_REQUEST_ID_LIST)
self.cs.assert_called('GET', '/os-tenant-networks')
self.assertTrue(len(nets) > 0)
self.assertGreater(len(nets), 0)
def test_get_tenant_network(self):
net = self.cs.tenant_networks.get(1)

View File

@ -25,6 +25,6 @@ class ListExtensionsTests(utils.TestCase):
all_exts = self.cs.list_extensions.show_all()
self.assert_request_id(all_exts, fakes.FAKE_REQUEST_ID_LIST)
self.cs.assert_called('GET', '/extensions')
self.assertTrue(len(all_exts) > 0)
self.assertGreater(len(all_exts), 0)
for r in all_exts:
self.assertTrue(len(r.summary) > 0)
self.assertGreater(len(r.summary), 0)