From 85b392f46c9f8de42ffbd3810e901563c18add9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9la=20Vancsics?= Date: Mon, 22 Aug 2016 10:28:12 +0200 Subject: [PATCH] Use more specific asserts in tests Instead of assertTrue and assertFalse use more specific asserts. They are compatible with Python 2.7[1] and 3.4[2] [1]: https://docs.python.org/2.7/library/unittest.html [2]: https://docs.python.org/3.4/library/unittest.html Change-Id: Id839997ff21c2b1fcf6701f4bc47babe61623817 --- tests/functional/test_cli_task.py | 4 ++-- .../plugins/openstack/scenarios/quotas/test_utils.py | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/functional/test_cli_task.py b/tests/functional/test_cli_task.py index 67ecc713..0b7de437 100644 --- a/tests/functional/test_cli_task.py +++ b/tests/functional/test_cli_task.py @@ -564,7 +564,7 @@ class TaskTestCase(unittest.TestCase): "deployment_id": deployment_id}) results = json.loads(rally("task results")) iterations_completed = len(results[0]["result"]) - self.assertTrue(iterations_completed < times) + self.assertLess(iterations_completed, times) def test_start_abort_on_sla_failure_max_seconds_constant(self): times = 100 @@ -734,7 +734,7 @@ class TaskTestCase(unittest.TestCase): iterations_completed = len(results[0]["result"]) # NOTE(msdubov): check that the task is really stopped before # the specified number of iterations - self.assertTrue(iterations_completed < RUNNER_TIMES) + self.assertLess(iterations_completed, RUNNER_TIMES) self.assertIn("aborted", rally("task status")) report = rally.gen_report_path(extension="html") rally("task report --out %s" % report) diff --git a/tests/unit/plugins/openstack/scenarios/quotas/test_utils.py b/tests/unit/plugins/openstack/scenarios/quotas/test_utils.py index ab68214e..47a88bef 100644 --- a/tests/unit/plugins/openstack/scenarios/quotas/test_utils.py +++ b/tests/unit/plugins/openstack/scenarios/quotas/test_utils.py @@ -76,14 +76,16 @@ class QuotasScenarioTestCase(test.ScenarioTestCase): scenario = utils.QuotasScenario(self.context) quotas = scenario._generate_quota_values(max_quota, "nova") for k, v in six.iteritems(quotas): - self.assertTrue(-1 <= v <= max_quota) + self.assertGreaterEqual(v, -1) + self.assertLessEqual(v, max_quota) def test__generate_quota_values_cinder(self): max_quota = 1024 scenario = utils.QuotasScenario(self.context) quotas = scenario._generate_quota_values(max_quota, "cinder") for k, v in six.iteritems(quotas): - self.assertTrue(-1 <= v <= max_quota) + self.assertGreaterEqual(v, -1) + self.assertLessEqual(v, max_quota) def test__generate_quota_values_neutron(self): max_quota = 1024 @@ -92,7 +94,8 @@ class QuotasScenarioTestCase(test.ScenarioTestCase): for v in six.itervalues(quotas): for v1 in six.itervalues(v): for v2 in six.itervalues(v1): - self.assertTrue(-1 <= v2 <= max_quota) + self.assertGreaterEqual(v2, -1) + self.assertLessEqual(v2, max_quota) def test__delete_quotas(self): tenant_id = "fake_tenant"