From dfcb265ae8041e12343737cd31c7b6c9fce679a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9la=20Vancsics?= Date: Mon, 22 Aug 2016 09:15:29 +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: Ifee66714db561fb329911395b2cfdd90c689b609 --- heat/tests/api/test_wsgi.py | 2 +- heat/tests/autoscaling/test_heat_scaling_group.py | 2 +- heat/tests/autoscaling/test_scaling_group.py | 6 ++++-- heat/tests/aws/test_instance.py | 12 ++++++------ heat/tests/aws/test_instance_network.py | 4 ++-- heat/tests/clients/test_clients.py | 4 ++-- heat/tests/clients/test_swift_client.py | 2 +- heat/tests/constraints/test_heat_constraints.py | 4 ++-- heat/tests/engine/test_dependencies.py | 2 +- heat/tests/engine/test_scheduler.py | 4 ++-- heat/tests/openstack/cinder/test_volume.py | 2 +- .../heat/test_instance_group_update_policy.py | 6 ++++-- heat/tests/openstack/heat/test_random_string.py | 2 +- heat/tests/openstack/heat/test_resource_group.py | 6 ++++-- heat/tests/openstack/nova/test_server.py | 12 ++++++------ heat/tests/openstack/nova/test_server_group.py | 2 +- heat/tests/openstack/swift/test_container.py | 2 +- heat/tests/test_engine_service.py | 4 ++-- heat/tests/test_lifecycle_plugin_utils.py | 2 +- heat/tests/test_metadata_refresh.py | 2 +- heat/tests/test_resource.py | 4 ++-- heat/tests/test_template_format.py | 9 +++++---- heat/tests/test_watch.py | 10 +++++----- .../functional/test_resource_chain.py | 8 ++++---- .../functional/test_stack_events.py | 2 +- .../scenario/test_server_software_config.py | 4 ++-- 26 files changed, 63 insertions(+), 56 deletions(-) diff --git a/heat/tests/api/test_wsgi.py b/heat/tests/api/test_wsgi.py index 85d91f4600..1eb33d3cfb 100644 --- a/heat/tests/api/test_wsgi.py +++ b/heat/tests/api/test_wsgi.py @@ -380,7 +380,7 @@ class JSONRequestDeserializerTest(common.HeatTestCase): def test_from_json_exceeds_max_json_mb(self): cfg.CONF.set_override('max_json_body_size', 10, enforce_type=True) body = json.dumps(['a'] * cfg.CONF.max_json_body_size) - self.assertTrue(len(body) > cfg.CONF.max_json_body_size) + self.assertGreater(len(body), cfg.CONF.max_json_body_size) error = self.assertRaises(exception.RequestLimitExceeded, wsgi.JSONRequestDeserializer().from_json, body) diff --git a/heat/tests/autoscaling/test_heat_scaling_group.py b/heat/tests/autoscaling/test_heat_scaling_group.py index a6f1d9c38b..0e04029d0f 100644 --- a/heat/tests/autoscaling/test_heat_scaling_group.py +++ b/heat/tests/autoscaling/test_heat_scaling_group.py @@ -523,7 +523,7 @@ class RollingUpdatePolicyTest(common.HeatTestCase): tmpl_batch_sz = int(tmpl_policy['max_batch_size']) policy = stack['my-group'].properties['rolling_updates'] self.assertTrue(policy) - self.assertTrue(len(policy) == 3) + self.assertEqual(3, len(policy)) self.assertEqual(1, int(policy['min_in_service'])) self.assertEqual(tmpl_batch_sz, int(policy['max_batch_size'])) self.assertEqual(1, policy['pause_time']) diff --git a/heat/tests/autoscaling/test_scaling_group.py b/heat/tests/autoscaling/test_scaling_group.py index 7834c2f498..9d9bceb056 100644 --- a/heat/tests/autoscaling/test_scaling_group.py +++ b/heat/tests/autoscaling/test_scaling_group.py @@ -631,7 +631,8 @@ class RollingUpdatePolicyTest(common.HeatTestCase): self.assertEqual(1, len(grp.update_policy)) self.assertIn('AutoScalingRollingUpdate', grp.update_policy) policy = grp.update_policy['AutoScalingRollingUpdate'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(1, int(policy['MinInstancesInService'])) self.assertEqual(tmpl_batch_sz, int(policy['MaxBatchSize'])) self.assertEqual('PT1S', policy['PauseTime']) @@ -646,7 +647,8 @@ class RollingUpdatePolicyTest(common.HeatTestCase): self.assertEqual(1, len(grp.update_policy)) self.assertIn('AutoScalingRollingUpdate', grp.update_policy) policy = grp.update_policy['AutoScalingRollingUpdate'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(0, int(policy['MinInstancesInService'])) self.assertEqual(1, int(policy['MaxBatchSize'])) self.assertEqual('PT0S', policy['PauseTime']) diff --git a/heat/tests/aws/test_instance.py b/heat/tests/aws/test_instance.py index 4ba93c3d2a..31c0fe9657 100644 --- a/heat/tests/aws/test_instance.py +++ b/heat/tests/aws/test_instance.py @@ -175,7 +175,7 @@ class InstancesTest(common.HeatTestCase): instance = self._create_test_instance(return_server, 'in_create') # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) expected_ip = return_server.networks['public'][0] expected_az = getattr(return_server, 'OS-EXT-AZ:availability_zone') @@ -197,7 +197,7 @@ class InstancesTest(common.HeatTestCase): instance = self._create_test_instance(return_server, 'create_with_bdm') # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) expected_ip = return_server.networks['public'][0] expected_az = getattr(return_server, 'OS-EXT-AZ:availability_zone') @@ -375,7 +375,7 @@ class InstancesTest(common.HeatTestCase): scheduler.TaskRunner(instance.create)() # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) expected_ip = return_server.networks['public'][0] expected_az = getattr(return_server, 'OS-EXT-AZ:availability_zone') @@ -638,7 +638,7 @@ class InstancesTest(common.HeatTestCase): return_server) self.m.ReplayAll() scheduler.TaskRunner(instance.create)() - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) self.m.VerifyAll() def test_instance_validate(self): @@ -671,7 +671,7 @@ class InstancesTest(common.HeatTestCase): instance.status = vm_status # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) d1 = {'server': self.fc.client.get_servers_detail()[1]['servers'][0]} d1['server']['status'] = vm_status @@ -706,7 +706,7 @@ class InstancesTest(common.HeatTestCase): instance.resource_id = '1234' # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) self.m.StubOutWithMock(self.fc.client, 'delete_servers_1234') self.fc.client.delete_servers_1234().AndRaise( diff --git a/heat/tests/aws/test_instance_network.py b/heat/tests/aws/test_instance_network.py index f0750747ed..dbfd174f56 100644 --- a/heat/tests/aws/test_instance_network.py +++ b/heat/tests/aws/test_instance_network.py @@ -168,7 +168,7 @@ class instancesTest(common.HeatTestCase): instance.resource_id = '1234' instance.status = vm_status # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) expected_ip = return_server.networks['public'][0] self.assertEqual(expected_ip, instance.FnGetAtt('PublicIp')) @@ -324,7 +324,7 @@ class instancesTest(common.HeatTestCase): return_server, 'in_create_wnic') # this makes sure the auto increment worked on instance creation - self.assertTrue(instance.id > 0) + self.assertGreater(instance.id, 0) expected_ip = return_server.networks['public'][0] self.assertEqual(expected_ip, instance.FnGetAtt('PublicIp')) diff --git a/heat/tests/clients/test_clients.py b/heat/tests/clients/test_clients.py index f192079fb7..80fd27e933 100644 --- a/heat/tests/clients/test_clients.py +++ b/heat/tests/clients/test_clients.py @@ -365,8 +365,8 @@ class TestClientPluginsInitialise(common.HeatTestCase): self.assertEqual({}, plugin._client_instances) self.assertTrue(clients.has_client(plugin_name)) self.assertIsInstance(plugin.service_types, list) - self.assertTrue(len(plugin.service_types) >= 1, - 'service_types is not defined for plugin') + self.assertGreaterEqual(len(plugin.service_types), 1, + 'service_types is not defined for plugin') @mock.patch.object(client_plugin.ClientPlugin, 'invalidate') def test_invalidate_all_clients(self, mock_invalidate): diff --git a/heat/tests/clients/test_swift_client.py b/heat/tests/clients/test_swift_client.py index afb289ba3a..3ceaadaa44 100644 --- a/heat/tests/clients/test_swift_client.py +++ b/heat/tests/clients/test_swift_client.py @@ -82,7 +82,7 @@ class SwiftUtilsTest(SwiftClientPluginTestCase): self.assertThat(url, matchers.MatchesRegex(regexp)) timeout = int(url.split('=')[-1]) - self.assertTrue(timeout < swift.MAX_EPOCH) + self.assertLess(timeout, swift.MAX_EPOCH) def test_get_temp_url_no_account_key(self): self.swift_client.url = ("http://fake-host.com:8080/v1/" diff --git a/heat/tests/constraints/test_heat_constraints.py b/heat/tests/constraints/test_heat_constraints.py index c32045aa01..22ebf8554e 100644 --- a/heat/tests/constraints/test_heat_constraints.py +++ b/heat/tests/constraints/test_heat_constraints.py @@ -61,8 +61,8 @@ class ResourceTypeConstraintTest(common.HeatTestCase): # Verify self.assertFalse(result) - self.assertTrue('OS::Heat::None,OS::Heat::RandomString' - in self.constraint._error_message) + self.assertIn('OS::Heat::None,OS::Heat::RandomString', + self.constraint._error_message) self.mock_env.get_class.assert_has_calls([mock.call(value[0]), mock.call(value[1])]) diff --git a/heat/tests/engine/test_dependencies.py b/heat/tests/engine/test_dependencies.py index 4ffd3dd863..9f6d0c82ba 100644 --- a/heat/tests/engine/test_dependencies.py +++ b/heat/tests/engine/test_dependencies.py @@ -183,7 +183,7 @@ class dependenciesTest(common.HeatTestCase): for n in ('last', 'middle'): self.assertIn(n, order, "'%s' not found in dependency order" % n) - self.assertTrue(order.index('last') > order.index('middle')) + self.assertGreater(order.index('last'), order.index('middle')) def test_simple_multilevel_partial(self): d = dependencies.Dependencies([('last', 'middle'), diff --git a/heat/tests/engine/test_scheduler.py b/heat/tests/engine/test_scheduler.py index f7109950a5..83fea5b66e 100644 --- a/heat/tests/engine/test_scheduler.py +++ b/heat/tests/engine/test_scheduler.py @@ -1283,8 +1283,8 @@ class TimeoutTest(common.HeatTestCase): eventlet.sleep(0.01) later = scheduler.Timeout(task, 10) - self.assertTrue(earlier < later) - self.assertTrue(later > earlier) + self.assertLess(earlier, later) + self.assertGreater(later, earlier) self.assertEqual(earlier, earlier) self.assertNotEqual(earlier, later) diff --git a/heat/tests/openstack/cinder/test_volume.py b/heat/tests/openstack/cinder/test_volume.py index e9dba63651..ba7ac985c2 100644 --- a/heat/tests/openstack/cinder/test_volume.py +++ b/heat/tests/openstack/cinder/test_volume.py @@ -1019,7 +1019,7 @@ class CinderVolumeTest(vt_base.BaseVolumeTest): self.patchobject(rsrc, '_store_config_default_properties') scheduler.TaskRunner(rsrc.create)() # this makes sure the auto increment worked on volume creation - self.assertTrue(rsrc.id > 0) + self.assertGreater(rsrc.id, 0) self.m.VerifyAll() diff --git a/heat/tests/openstack/heat/test_instance_group_update_policy.py b/heat/tests/openstack/heat/test_instance_group_update_policy.py index 9add242492..36a1919cf5 100644 --- a/heat/tests/openstack/heat/test_instance_group_update_policy.py +++ b/heat/tests/openstack/heat/test_instance_group_update_policy.py @@ -181,7 +181,8 @@ class InstanceGroupTest(common.HeatTestCase): self.assertEqual(1, len(grp.update_policy)) self.assertIn('RollingUpdate', grp.update_policy) policy = grp.update_policy['RollingUpdate'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(1, int(policy['MinInstancesInService'])) self.assertEqual(2, int(policy['MaxBatchSize'])) self.assertEqual('PT1S', policy['PauseTime']) @@ -196,7 +197,8 @@ class InstanceGroupTest(common.HeatTestCase): self.assertEqual(1, len(grp.update_policy)) self.assertIn('RollingUpdate', grp.update_policy) policy = grp.update_policy['RollingUpdate'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(0, int(policy['MinInstancesInService'])) self.assertEqual(1, int(policy['MaxBatchSize'])) self.assertEqual('PT0S', policy['PauseTime']) diff --git a/heat/tests/openstack/heat/test_random_string.py b/heat/tests/openstack/heat/test_random_string.py index bc2a089891..82b45c34aa 100644 --- a/heat/tests/openstack/heat/test_random_string.py +++ b/heat/tests/openstack/heat/test_random_string.py @@ -92,7 +92,7 @@ Resources: return stack def assert_min(self, pattern, string, minimum): - self.assertTrue(len(re.findall(pattern, string)) >= minimum) + self.assertGreaterEqual(len(re.findall(pattern, string)), minimum) def test_random_string(self): stack = self.create_stack(self.template_random_string) diff --git a/heat/tests/openstack/heat/test_resource_group.py b/heat/tests/openstack/heat/test_resource_group.py index d2bd72b16b..6d59bcbbe1 100644 --- a/heat/tests/openstack/heat/test_resource_group.py +++ b/heat/tests/openstack/heat/test_resource_group.py @@ -992,7 +992,8 @@ class RollingUpdatePolicyTest(common.HeatTestCase): self.assertEqual(2, len(grp.update_policy)) self.assertIn('rolling_update', grp.update_policy) policy = grp.update_policy['rolling_update'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(1, int(policy['min_in_service'])) self.assertEqual(tmpl_batch_sz, int(policy['max_batch_size'])) self.assertEqual(1, policy['pause_time']) @@ -1006,7 +1007,8 @@ class RollingUpdatePolicyTest(common.HeatTestCase): self.assertEqual(2, len(grp.update_policy)) self.assertIn('rolling_update', grp.update_policy) policy = grp.update_policy['rolling_update'] - self.assertTrue(policy and len(policy) > 0) + self.assertIsNotNone(policy) + self.assertGreater(len(policy), 0) self.assertEqual(0, int(policy['min_in_service'])) self.assertEqual(1, int(policy['max_batch_size'])) self.assertEqual(0, policy['pause_time']) diff --git a/heat/tests/openstack/nova/test_server.py b/heat/tests/openstack/nova/test_server.py index 15c763d1f2..f275adbfc8 100644 --- a/heat/tests/openstack/nova/test_server.py +++ b/heat/tests/openstack/nova/test_server.py @@ -394,7 +394,7 @@ class ServersTest(common.HeatTestCase): server = self._create_test_server(return_server, server_name) # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) interfaces = [ self._create_fake_iface('1234', 'fa:16:3e:8c:22:aa', '4.5.6.7'), @@ -1066,7 +1066,7 @@ class ServersTest(common.HeatTestCase): _, kwargs = mock_create.call_args self.assertEqual(kwargs['scheduler_hints'], scheduler_hints) # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) def test_check_maximum(self): msg = 'test_check_maximum' @@ -1451,7 +1451,7 @@ class ServersTest(common.HeatTestCase): server.resource_id = '1234' # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) side_effect = [server, fakes_nova.fake_exception()] self.patchobject(self.fc.servers, 'get', side_effect=side_effect) @@ -1465,7 +1465,7 @@ class ServersTest(common.HeatTestCase): server.resource_id = '1234' # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) self.patchobject(self.fc.client, 'delete_servers_1234', side_effect=fakes_nova.fake_exception()) @@ -1479,7 +1479,7 @@ class ServersTest(common.HeatTestCase): server.resource_id = '1234' # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) def make_error(*args): return_server.status = "ERROR" @@ -1525,7 +1525,7 @@ class ServersTest(common.HeatTestCase): server.resource_id = '1234' # this makes sure the auto increment worked on server creation - self.assertTrue(server.id > 0) + self.assertGreater(server.id, 0) def make_soft_delete(*args): return_server.status = "SOFT_DELETED" diff --git a/heat/tests/openstack/nova/test_server_group.py b/heat/tests/openstack/nova/test_server_group.py index 1954f0cff9..a8129fa9e0 100644 --- a/heat/tests/openstack/nova/test_server_group.py +++ b/heat/tests/openstack/nova/test_server_group.py @@ -73,7 +73,7 @@ class NovaServerGroupTest(common.HeatTestCase): n = name def fake_create(name, policies): - self.assertTrue(len(name) > 1) + self.assertGreater(len(name), 1) return FakeGroup(n) self.sg_mgr.create = fake_create scheduler.TaskRunner(self.sg.create)() diff --git a/heat/tests/openstack/swift/test_container.py b/heat/tests/openstack/swift/test_container.py index f330443a28..9a7eb3d1a6 100644 --- a/heat/tests/openstack/swift/test_container.py +++ b/heat/tests/openstack/swift/test_container.py @@ -153,7 +153,7 @@ class SwiftTest(common.HeatTestCase): # Verify Expected Calls mock_put.assert_called_once_with(container_name, {}) - self.assertTrue(mock_head.call_count > 0) + self.assertGreater(mock_head.call_count, 0) @mock.patch('swiftclient.client.Connection.put_container') def test_public_read(self, mock_put): diff --git a/heat/tests/test_engine_service.py b/heat/tests/test_engine_service.py index 72fcf3b620..1b8a9fa09c 100644 --- a/heat/tests/test_engine_service.py +++ b/heat/tests/test_engine_service.py @@ -122,7 +122,7 @@ class StackCreateTest(common.HeatTestCase): stack.create() self.assertIsNotNone(stack['WebServer']) - self.assertTrue(int(stack['WebServer'].resource_id) > 0) + self.assertGreater(int(stack['WebServer'].resource_id), 0) self.assertNotEqual(stack['WebServer'].ipaddress, '0.0.0.0') def test_wordpress_single_instance_stack_adopt(self): @@ -188,7 +188,7 @@ class StackCreateTest(common.HeatTestCase): self.assertIsNotNone(db_s) self.assertIsNotNone(stack['WebServer']) - self.assertTrue(int(stack['WebServer'].resource_id) > 0) + self.assertGreater(int(stack['WebServer'].resource_id), 0) self.patchobject(fc.servers, 'delete', side_effect=fakes_nova.fake_exception()) diff --git a/heat/tests/test_lifecycle_plugin_utils.py b/heat/tests/test_lifecycle_plugin_utils.py index bda1bc23b8..a00fd4921e 100644 --- a/heat/tests/test_lifecycle_plugin_utils.py +++ b/heat/tests/test_lifecycle_plugin_utils.py @@ -56,7 +56,7 @@ class LifecyclePluginUtilsTest(common.HeatTestCase): self.assertIsNotNone(pp_cinstances) self.assertTrue(self.is_iterable(pp_cinstances), "not iterable: %s" % pp_cinstances) - self.assertTrue(len(pp_cinstances) == 1) + self.assertEqual(1, len(pp_cinstances)) self.assertEqual(TestLifecycleCallout1, pp_cinstances[0].__class__) def test_do_pre_and_post_callouts(self): diff --git a/heat/tests/test_metadata_refresh.py b/heat/tests/test_metadata_refresh.py index 4fdf2d6c04..0675b735fc 100644 --- a/heat/tests/test_metadata_refresh.py +++ b/heat/tests/test_metadata_refresh.py @@ -284,7 +284,7 @@ class WaitConditionMetadataUpdateTest(common.HeatTestCase): jsonutils.loads(inst.metadata_get(refresh=True)['test'])) # Verify outgoing calls - self.assertTrue(mock_available.call_count > 0) + self.assertGreater(mock_available.call_count, 0) self.assertEqual(2, mock_handle.call_count) self.assertEqual(2, mock_check.call_count) diff --git a/heat/tests/test_resource.py b/heat/tests/test_resource.py index 3213110901..7c8a284340 100644 --- a/heat/tests/test_resource.py +++ b/heat/tests/test_resource.py @@ -4229,7 +4229,7 @@ class TestResourceMapping(common.HeatTestCase): type_elements = r_type.split('::') # type has fixed format # Platform type::Service/Type::Optional Sub-sections::Name - self.assertTrue(len(type_elements) >= 3) + self.assertGreaterEqual(len(type_elements), 3) # type should be OS or AWS self.assertIn(type_elements[0], ('AWS', 'OS')) # check that value is a class object @@ -4257,4 +4257,4 @@ class TestResourceMapping(common.HeatTestCase): # that there is no regressions # It's soft check and should not be a cause of the merge conflict # Feel free to update it in some separate patch - self.assertTrue(num_of_types >= 137) + self.assertGreaterEqual(num_of_types, 137) diff --git a/heat/tests/test_template_format.py b/heat/tests/test_template_format.py index d3b8afe037..c007ebbd59 100644 --- a/heat/tests/test_template_format.py +++ b/heat/tests/test_template_format.py @@ -47,9 +47,10 @@ class JsonToYamlTest(common.HeatTestCase): if template_test_count >= self.expected_test_count: break - self.assertTrue(template_test_count >= self.expected_test_count, - 'Expected at least %d templates to be tested, not %d' % - (self.expected_test_count, template_test_count)) + self.assertGreaterEqual( + template_test_count, self.expected_test_count, + 'Expected at least %d templates to be tested, not %d' % + (self.expected_test_count, template_test_count)) def compare_json_vs_yaml(self, json_str, yml_str): yml = template_format.parse(yml_str) @@ -103,7 +104,7 @@ class YamlMinimalTest(common.HeatTestCase): config.cfg.CONF.max_template_size / 3) limit = config.cfg.CONF.max_template_size long_yaml = yaml.safe_dump(template) - self.assertTrue(len(long_yaml) > limit) + self.assertGreater(len(long_yaml), limit) ex = self.assertRaises(exception.RequestLimitExceeded, template_format.parse, long_yaml) msg = ('Request limit exceeded: Template size (%(actual_len)s ' diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index f48f19df4f..f22ca4639a 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -512,7 +512,7 @@ class WatchRuleTest(common.HeatTestCase): actions = wr.evaluate() self.assertEqual('ALARM', wr.state) self.assertEqual(['DummyAction'], actions) - self.assertTrue(mock_get_resource.call_count > 0) + self.assertGreater(mock_get_resource.call_count, 0) @mock.patch('heat.engine.stack.Stack.resource_by_refid') def test_rule_actions_alarm_two_actions(self, mock_get_resource): @@ -542,7 +542,7 @@ class WatchRuleTest(common.HeatTestCase): actions = wr.evaluate() self.assertEqual('ALARM', wr.state) self.assertEqual(['DummyAction', 'DummyAction'], actions) - self.assertTrue(mock_get_resource.call_count > 0) + self.assertGreater(mock_get_resource.call_count, 0) @mock.patch('heat.engine.stack.Stack.resource_by_refid') def test_rule_actions_ok_alarm(self, mock_get_resource): @@ -583,7 +583,7 @@ class WatchRuleTest(common.HeatTestCase): actions = wr.evaluate() self.assertEqual('NORMAL', wr.state) self.assertEqual(['DummyAction'], actions) - self.assertTrue(mock_get_resource.call_count > 0) + self.assertGreater(mock_get_resource.call_count, 0) @mock.patch('heat.engine.stack.Stack.resource_by_refid') def test_rule_actions_nodata(self, mock_get_resource): @@ -622,7 +622,7 @@ class WatchRuleTest(common.HeatTestCase): actions = wr.evaluate() self.assertEqual('NODATA', wr.state) self.assertEqual(['DummyAction'], actions) - self.assertTrue(mock_get_resource.call_count > 0) + self.assertGreater(mock_get_resource.call_count, 0) @mock.patch('heat.engine.stack.Stack.resource_by_refid') def test_to_ceilometer(self, mock_get_resource): @@ -951,7 +951,7 @@ class WatchRuleTest(common.HeatTestCase): actions = wr.set_watch_state(watchrule.WatchRule.ALARM) self.assertEqual(['DummyAction'], actions) - self.assertTrue(mock_get_resource.call_count > 0) + self.assertGreater(mock_get_resource.call_count, 0) def test_set_watch_state_invalid(self): # Setup diff --git a/heat_integrationtests/functional/test_resource_chain.py b/heat_integrationtests/functional/test_resource_chain.py index 1086e74c4d..2898ebefbc 100644 --- a/heat_integrationtests/functional/test_resource_chain.py +++ b/heat_integrationtests/functional/test_resource_chain.py @@ -58,7 +58,7 @@ class ResourceChainTests(functional_base.FunctionalTestsBase): # Verify stack = self.client.stacks.get(stack_id) - self.assertTrue(stack is not None) + self.assertIsNotNone(stack) # Top-level resource for chain expected = {'my-chain': 'OS::Heat::ResourceChain'} @@ -74,15 +74,15 @@ class ResourceChainTests(functional_base.FunctionalTestsBase): # Outputs resource_ids = self._stack_output(stack, 'resource-ids') - self.assertTrue(resource_ids is not None) + self.assertIsNotNone(resource_ids) self.assertEqual(2, len(resource_ids)) resource_value = self._stack_output(stack, 'resource-0-value') - self.assertTrue(resource_value is not None) + self.assertIsNotNone(resource_value) self.assertEqual(8, len(resource_value)) # from parameter resource_attrs = self._stack_output(stack, 'all-resource-attrs') - self.assertTrue(resource_attrs is not None) + self.assertIsNotNone(resource_attrs) self.assertIsInstance(resource_attrs, dict) self.assertEqual(2, len(resource_attrs)) self.assertEqual(8, len(resource_attrs['0'])) diff --git a/heat_integrationtests/functional/test_stack_events.py b/heat_integrationtests/functional/test_stack_events.py index 3638fab758..d5a7fada90 100644 --- a/heat_integrationtests/functional/test_stack_events.py +++ b/heat_integrationtests/functional/test_stack_events.py @@ -74,7 +74,7 @@ outputs: stack_event.resource_name) # Resource events are a subset of the original stack event list - self.assertTrue(len(resource_events) < len(stack_events)) + self.assertLess(len(resource_events), len(stack_events)) # Get the event details for each resource event for resource_event in resource_events: diff --git a/heat_integrationtests/scenario/test_server_software_config.py b/heat_integrationtests/scenario/test_server_software_config.py index df35042323..f4c7da53f0 100644 --- a/heat_integrationtests/scenario/test_server_software_config.py +++ b/heat_integrationtests/scenario/test_server_software_config.py @@ -100,7 +100,7 @@ class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase): res1['result']) self.assertEqual(0, res1['status_code']) self.assertEqual('Output to stderr\n', res1['stderr']) - self.assertTrue(len(res1['stdout']) > 0) + self.assertGreater(len(res1['stdout']), 0) res2 = self._stack_output(stack, 'res2') self.assertEqual( @@ -118,7 +118,7 @@ class SoftwareConfigIntegrationTest(scenario_base.ScenarioTestsBase): res3['result']) self.assertEqual(0, res3['status_code']) self.assertEqual('', res3['stderr']) - self.assertTrue(len(res1['stdout']) > 0) + self.assertGreater(len(res1['stdout']), 0) dep1_resource = self.client.resources.get(sid, 'dep1') dep1_id = dep1_resource.physical_resource_id