From a72f2c6fb7105d29afe23252273026ad385181b3 Mon Sep 17 00:00:00 2001 From: "Joe H. Rahme" Date: Mon, 11 Jul 2016 16:28:19 +0200 Subject: [PATCH] Removes explicit looping over dict .keys() method Looping over the .keys() method of a dictionary is an anti-pattern. In fact, the method is actually creating a new list which is redundant and unnecessary. Looping over a dictionary implicitly loops over its keys. Change-Id: I937d3f060bf95bb86e50fcb5dec8def524f6208e --- tempest/api/data_processing/base.py | 2 +- tempest/api/orchestration/stacks/test_soft_conf.py | 2 +- tempest/common/cred_provider.py | 2 +- tempest/lib/auth.py | 2 +- tempest/lib/cmd/skip_tracker.py | 2 +- tempest/scenario/test_aggregates_basic_ops.py | 2 +- tempest/tests/lib/fake_auth_provider.py | 2 +- tempest/tests/lib/test_credentials.py | 2 +- tempest/tests/test_service_clients.py | 4 ++-- tools/skip_tracker.py | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tempest/api/data_processing/base.py b/tempest/api/data_processing/base.py index decccf3806..d5ba76cb8e 100644 --- a/tempest/api/data_processing/base.py +++ b/tempest/api/data_processing/base.py @@ -349,7 +349,7 @@ class BaseDataProcessingTest(tempest.test.BaseTestCase): return None for plugin in CONF.data_processing_feature_enabled.plugins: - if plugin in DEFAULT_TEMPLATES.keys(): + if plugin in DEFAULT_TEMPLATES: break else: plugin = '' diff --git a/tempest/api/orchestration/stacks/test_soft_conf.py b/tempest/api/orchestration/stacks/test_soft_conf.py index 6a4e2b932e..aa0b46add6 100644 --- a/tempest/api/orchestration/stacks/test_soft_conf.py +++ b/tempest/api/orchestration/stacks/test_soft_conf.py @@ -45,7 +45,7 @@ class TestSoftwareConfig(base.BaseOrchestrationTest): def _validate_config(self, configuration, api_config): # Assert all expected keys are present with matching data - for k in configuration.keys(): + for k in configuration: self.assertEqual(configuration[k], api_config['software_config'][k]) diff --git a/tempest/common/cred_provider.py b/tempest/common/cred_provider.py index bf6c5379ca..1b450ab9f5 100644 --- a/tempest/common/cred_provider.py +++ b/tempest/common/cred_provider.py @@ -94,7 +94,7 @@ class TestResources(object): self.router) def set_resources(self, **kwargs): - for key in kwargs.keys(): + for key in kwargs: if hasattr(self, key): setattr(self, key, kwargs[key]) diff --git a/tempest/lib/auth.py b/tempest/lib/auth.py index 425758fd9d..54a7002905 100644 --- a/tempest/lib/auth.py +++ b/tempest/lib/auth.py @@ -665,7 +665,7 @@ class Credentials(object): msg = ('Cannot have conflicting values for %s and %s' % (key1, key2)) raise exceptions.InvalidCredentials(msg) - for key in attr.keys(): + for key in attr: if key in self.ATTRIBUTES: setattr(self, key, attr[key]) else: diff --git a/tempest/lib/cmd/skip_tracker.py b/tempest/lib/cmd/skip_tracker.py index f35b14cb8c..d95aa4664d 100755 --- a/tempest/lib/cmd/skip_tracker.py +++ b/tempest/lib/cmd/skip_tracker.py @@ -103,7 +103,7 @@ def find_skips_in_file(path): def get_results(result_dict): results = [] - for bug_no in result_dict.keys(): + for bug_no in result_dict: for method in result_dict[bug_no]: results.append((method, bug_no)) return results diff --git a/tempest/scenario/test_aggregates_basic_ops.py b/tempest/scenario/test_aggregates_basic_ops.py index cace90b1c3..086b82d907 100644 --- a/tempest/scenario/test_aggregates_basic_ops.py +++ b/tempest/scenario/test_aggregates_basic_ops.py @@ -74,7 +74,7 @@ class TestAggregatesBasicOps(manager.ScenarioTest): self.assertEqual(aggregate_name, aggregate['name']) self.assertEqual(azone, aggregate['availability_zone']) self.assertEqual(hosts, aggregate['hosts']) - for meta_key in metadata.keys(): + for meta_key in metadata: self.assertIn(meta_key, aggregate['metadata']) self.assertEqual(metadata[meta_key], aggregate['metadata'][meta_key]) diff --git a/tempest/tests/lib/fake_auth_provider.py b/tempest/tests/lib/fake_auth_provider.py index 8095453b9a..fa8ab475ad 100644 --- a/tempest/tests/lib/fake_auth_provider.py +++ b/tempest/tests/lib/fake_auth_provider.py @@ -31,5 +31,5 @@ class FakeAuthProvider(object): class FakeCredentials(object): def __init__(self, creds_dict): - for key in creds_dict.keys(): + for key in creds_dict: setattr(self, key, creds_dict[key]) diff --git a/tempest/tests/lib/test_credentials.py b/tempest/tests/lib/test_credentials.py index b6f2cf602a..c910d6d6d9 100644 --- a/tempest/tests/lib/test_credentials.py +++ b/tempest/tests/lib/test_credentials.py @@ -99,7 +99,7 @@ class KeystoneV2CredentialsTests(CredentialsTests): def _test_is_not_valid(self, ignore_key): creds = self._get_credentials() - for attr in self.attributes.keys(): + for attr in self.attributes: if attr == ignore_key: continue temp_attr = getattr(creds, attr) diff --git a/tempest/tests/test_service_clients.py b/tempest/tests/test_service_clients.py index d0158c7f7b..a559086ef3 100644 --- a/tempest/tests/test_service_clients.py +++ b/tempest/tests/test_service_clients.py @@ -77,8 +77,8 @@ class TestServiceClients(base.TestCase): uri = 'fake_uri' _manager = service_clients.ServiceClients(creds, identity_uri=uri, client_parameters=params) - self.assertIn('fake_service1', _manager.parameters.keys()) - for _key in expeted_params.keys(): + self.assertIn('fake_service1', _manager.parameters) + for _key in expeted_params: self.assertIn(_key, _manager.parameters['fake_service1'].keys()) self.assertEqual(expeted_params[_key], _manager.parameters['fake_service1'].get(_key)) diff --git a/tools/skip_tracker.py b/tools/skip_tracker.py index b554514ff3..55f41a679f 100755 --- a/tools/skip_tracker.py +++ b/tools/skip_tracker.py @@ -95,7 +95,7 @@ def find_skips_in_file(path): def get_results(result_dict): results = [] - for bug_no in result_dict.keys(): + for bug_no in result_dict: for method in result_dict[bug_no]: results.append((method, bug_no)) return results