From 6d21f3944531f281fef9af898c1972c763e82b81 Mon Sep 17 00:00:00 2001 From: Amir Mofakhar Date: Thu, 12 Apr 2018 11:42:36 +0200 Subject: [PATCH] Update pep8 checks * set the maximum line length to 100 * cleaned up the codes for pep8 Change-Id: I5d62c9925b10b18c7c8e4ce93ef7c5d2ffec3f8e Signed-off-by: Amir Mofakhar --- .gitignore | 1 + .../services/log_search_client.py | 2 +- .../tests/api/test_alarms.py | 52 +++++++++++-------- .../tests/api/test_alarms_count.py | 13 +++-- .../tests/api/test_notification_methods.py | 29 ++++++----- .../tests/api/test_statistics.py | 15 ++++-- tox.ini | 7 +-- 7 files changed, 68 insertions(+), 51 deletions(-) diff --git a/.gitignore b/.gitignore index 59b35f5..1406240 100644 --- a/.gitignore +++ b/.gitignore @@ -54,6 +54,7 @@ ChangeLog *~ .*.swp .*sw? +.idea # Files created by releasenotes build releasenotes/build diff --git a/monasca_tempest_tests/services/log_search_client.py b/monasca_tempest_tests/services/log_search_client.py index 962d611..5dde415 100644 --- a/monasca_tempest_tests/services/log_search_client.py +++ b/monasca_tempest_tests/services/log_search_client.py @@ -51,7 +51,7 @@ class LogsSearchClient(rest_client.RestClient): uri = '_msearch' body = """ {"index" : "*", "search_type" : "dfs_query_then_fetch"} - {"query" : {"match" : {"message":" """+message+""" "}}} + {"query" : {"match" : {"message":" """ + message + """ "}}} """ response, body = self.post(self._uri(uri), body, headers) self.expected_success(200, response.status) diff --git a/monasca_tempest_tests/tests/api/test_alarms.py b/monasca_tempest_tests/tests/api/test_alarms.py index 6ad991e..06782bc 100644 --- a/monasca_tempest_tests/tests/api/test_alarms.py +++ b/monasca_tempest_tests/tests/api/test_alarms.py @@ -458,7 +458,8 @@ class TestAlarms(base.BaseMonascaTest): @decorators.attr(type="gate") def test_list_alarms_by_offset_limit(self): definition_ids, expected_metric = self._create_alarms_for_test_alarms(num=3) - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name']) + resp, response_body = self.monasca_client.list_alarms('?metric_name=' + + expected_metric['name']) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) elements = response_body['elements'] @@ -500,11 +501,13 @@ class TestAlarms(base.BaseMonascaTest): @decorators.attr(type="gate") def test_list_alarms_sort_by(self): alarm_definition_ids, expected_metric = self._create_alarms_for_test_alarms(num=3) - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name']) + resp, response_body = self.monasca_client.list_alarms('?metric_name=' + + expected_metric['name']) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'] + + resp, response_body = self.monasca_client.list_alarms('?metric_name=' + + expected_metric['name'] + '&sort_by=created_timestamp') self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) @@ -513,8 +516,8 @@ class TestAlarms(base.BaseMonascaTest): last_timestamp = elements[0]['created_timestamp'] for element in elements: assert element['created_timestamp'] >= last_timestamp, \ - "Created_timestamps are not in sorted order {} came before {}".format(last_timestamp, - element['created_timestamp']) + "Created_timestamps are not in sorted " \ + "order {} came before {}".format(last_timestamp, element['created_timestamp']) last_timestamp = element['created_timestamp'] # Set link and lifecycle_state to sort in opposite order @@ -561,13 +564,14 @@ class TestAlarms(base.BaseMonascaTest): @decorators.attr(type='gate') def test_list_alarms_sort_by_asc_desc(self): alarm_definition_ids, expected_metric = self._create_alarms_for_test_alarms(num=3) - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name']) + resp, response_body = self.monasca_client.list_alarms('?metric_name=' + + expected_metric['name']) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'] + - '&sort_by=' + - urlparse.quote('created_timestamp asc')) + resp, response_body = self.monasca_client.list_alarms( + '?metric_name=' + expected_metric['name'] + + '&sort_by=' + urlparse.quote('created_timestamp asc')) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) @@ -575,13 +579,13 @@ class TestAlarms(base.BaseMonascaTest): last_timestamp = elements[0]['created_timestamp'] for element in elements: assert element['created_timestamp'] >= last_timestamp,\ - "Created_timestamps are not in ascending order {} came before {}".format(last_timestamp, - element['created_timestamp']) + "Created_timestamps are not in ascending" \ + " order {} came before {}".format(last_timestamp, element['created_timestamp']) last_timestamp = element['created_timestamp'] - resp, response_body = self.monasca_client.list_alarms('?metric_name=' + expected_metric['name'] + - '&sort_by=' + - urlparse.quote('created_timestamp desc')) + resp, response_body = self.monasca_client.list_alarms( + '?metric_name=' + expected_metric['name'] + + '&sort_by=' + urlparse.quote('created_timestamp desc')) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) @@ -589,8 +593,8 @@ class TestAlarms(base.BaseMonascaTest): last_timestamp = elements[0]['created_timestamp'] for element in elements: assert element['created_timestamp'] <= last_timestamp,\ - "Created_timestamps are not in descending order {} came before {}".format(last_timestamp, - element['created_timestamp']) + "Created_timestamps are not in descending" \ + " order {} came before {}".format(last_timestamp, element['created_timestamp']) last_timestamp = element['created_timestamp'] @decorators.attr(type="gate") @@ -624,11 +628,13 @@ class TestAlarms(base.BaseMonascaTest): self.assertEqual(204, resp.status) self._wait_for_alarms(3, alarm_def_id) - resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + alarm_def_id) + resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + + alarm_def_id) self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) - resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + alarm_def_id + + resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + + alarm_def_id + '&sort_by=alarm_id') self._verify_list_alarms_elements(resp, response_body, expect_num_elements=3) @@ -641,22 +647,24 @@ class TestAlarms(base.BaseMonascaTest): element['id']) previous_id = element['id'] - resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + alarm_def_id + + resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + + alarm_def_id + '&sort_by=alarm_id&limit=1') self.assertEqual(200, resp.status) elements = response_body['elements'] self.assertEqual(1, len(elements)) self.assertEqual(full_elements[0]['id'], elements[0]['id']) - resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + alarm_def_id + + resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + + alarm_def_id + '&sort_by=alarm_id&offset=1') self.assertEqual(200, resp.status) elements = response_body['elements'] self.assertEqual(2, len(elements)) self.assertEqual(full_elements[1]['id'], elements[0]['id']) - resp, response_body = self.monasca_client.list_alarms('?alarm_definition_id=' + alarm_def_id + - '&sort_by=state_updated_timestamp&offset=1') + resp, response_body = self.monasca_client.list_alarms( + '?alarm_definition_id=' + alarm_def_id + '&sort_by=state_updated_timestamp&offset=1') self.assertEqual(200, resp.status) elements = response_body['elements'] self.assertEqual(2, len(elements)) diff --git a/monasca_tempest_tests/tests/api/test_alarms_count.py b/monasca_tempest_tests/tests/api/test_alarms_count.py index a6dddd6..08e76b6 100644 --- a/monasca_tempest_tests/tests/api/test_alarms_count.py +++ b/monasca_tempest_tests/tests/api/test_alarms_count.py @@ -125,7 +125,8 @@ class TestAlarmsCount(base.BaseMonascaTest): if resp.status == 201: cls.alarm_definition_ids.append(response_body['id']) else: - msg = "Failed to create alarm_definition during setup: {} {}".format(resp.status, response_body) + msg = "Failed to create alarm_definition during setup: {} {}".format(resp.status, + response_body) assert False, msg # Give Thresh time to process the new Alarm Definitions @@ -159,7 +160,8 @@ class TestAlarmsCount(base.BaseMonascaTest): # time.sleep(15) return - msg = "Failed to create all specified alarms during setup, alarm_count was {}".format(alarm_count) + msg = "Failed to create all specified alarms" \ + " during setup, alarm_count was {}".format(alarm_count) assert False, msg @classmethod @@ -300,8 +302,8 @@ class TestAlarmsCount(base.BaseMonascaTest): self._verify_counts_format(response_body, group_by=list(GROUP_BY_ALLOWED_PARAMS)) # Expect duplicates - msg = "Not enough distinct counts. Expected at least {}, found {}".format(expected_num_count, - len(response_body['counts'])) + msg = "Not enough distinct counts. Expected at " \ + "least {}, found {}".format(expected_num_count, len(response_body['counts'])) assert expected_num_count <= len(response_body['counts']), msg @decorators.attr(type='gate') @@ -340,7 +342,8 @@ class TestAlarmsCount(base.BaseMonascaTest): @decorators.attr(type=['negative']) def test_invalid_offset(self): self.assertRaises(exceptions.UnprocessableEntity, - self.monasca_client.count_alarms, "?group_by=metric_name&offset=not_an_int") + self.monasca_client.count_alarms, + "?group_by=metric_name&offset=not_an_int") @decorators.attr(type='gate') def test_limit_and_offset(self): diff --git a/monasca_tempest_tests/tests/api/test_notification_methods.py b/monasca_tempest_tests/tests/api/test_notification_methods.py index adc228a..4f6f5e6 100644 --- a/monasca_tempest_tests/tests/api/test_notification_methods.py +++ b/monasca_tempest_tests/tests/api/test_notification_methods.py @@ -203,7 +203,8 @@ class TestNotificationMethods(base.BaseMonascaTest): self.monasca_client.create_notifications, notification) - # The below tests are making sure that we accept passing in case insensitive types and that we still validate the + # The below tests are making sure that we accept passing in case insensitive types + # and that we still validate the # address if the types are case insensitive @decorators.attr(type="gate") def test_create_notification_method_webhook_with_lower_case_type(self): @@ -271,9 +272,10 @@ class TestNotificationMethods(base.BaseMonascaTest): @decorators.attr(type=['negative']) def test_create_notification_method_with_invalid_type(self): notification = helpers.create_notification(type='random') - self.assertRaises((exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), - self.monasca_client.create_notifications, - notification) + self.assertRaises( + (exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) @decorators.attr(type="gate") @decorators.attr(type=['negative']) @@ -662,10 +664,11 @@ class TestNotificationMethods(base.BaseMonascaTest): notification) id = response_body['id'] self.assertEqual(201, resp.status) - self.assertRaises((exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), - self.monasca_client.update_notification_method, id, - name=response_body['name'], type='random', - address=response_body['address'], period=0) + self.assertRaises( + (exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), + self.monasca_client.update_notification_method, + id, name=response_body['name'], type='random', + address=response_body['address'], period=0) resp, response_body = \ self.monasca_client.delete_notification_method(id) self.assertEqual(204, resp.status) @@ -967,8 +970,9 @@ class TestNotificationMethods(base.BaseMonascaTest): notification) id = response_body['id'] self.assertEqual(201, resp.status) - self.assertRaises((exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), - self.monasca_client.patch_notification_method, id, type='random') + self.assertRaises( + (exceptions.BadRequest, exceptions.NotFound, exceptions.UnprocessableEntity), + self.monasca_client.patch_notification_method, id, type='random') resp, response_body = \ self.monasca_client.delete_notification_method(id) self.assertEqual(204, resp.status) @@ -984,8 +988,9 @@ class TestNotificationMethods(base.BaseMonascaTest): self.assertEqual(201, resp.status) new_address_long = "x" * ( constants.MAX_NOTIFICATION_METHOD_ADDRESS_LENGTH + 1) - self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), - self.monasca_client.patch_notification_method, id, address=new_address_long) + self.assertRaises( + (exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.patch_notification_method, id, address=new_address_long) resp, response_body = \ self.monasca_client.delete_notification_method(id) self.assertEqual(204, resp.status) diff --git a/monasca_tempest_tests/tests/api/test_statistics.py b/monasca_tempest_tests/tests/api/test_statistics.py index 47f979d..02a9c10 100644 --- a/monasca_tempest_tests/tests/api/test_statistics.py +++ b/monasca_tempest_tests/tests/api/test_statistics.py @@ -74,7 +74,8 @@ class TestStatistics(base.BaseMonascaTest): time.sleep(constants.RETRY_WAIT_SECS) if num_measurements < MIN_REQUIRED_MEASUREMENTS: - assert False, "Required {} measurements, found {}".format(MIN_REQUIRED_MEASUREMENTS, num_measurements) + assert False, "Required {} measurements, found {}".format(MIN_REQUIRED_MEASUREMENTS, + num_measurements) cls._end_timestamp = cls._start_timestamp + 3000 cls._end_time_iso = helpers.timestamp_to_iso(cls._end_timestamp) @@ -84,13 +85,17 @@ class TestStatistics(base.BaseMonascaTest): cls._group_by_end_time_iso = helpers.timestamp_to_iso(cls._start_timestamp + 4000) group_by_metrics = [ - helpers.create_metric(name=name2, dimensions={'key1': 'value1', 'key2': 'value5', 'key3': 'value7'}, + helpers.create_metric(name=name2, + dimensions={'key1': 'value1', 'key2': 'value5', 'key3': 'value7'}, timestamp=cls._start_timestamp + 1, value=2), - helpers.create_metric(name=name2, dimensions={'key1': 'value2', 'key2': 'value5', 'key3': 'value7'}, + helpers.create_metric(name=name2, + dimensions={'key1': 'value2', 'key2': 'value5', 'key3': 'value7'}, timestamp=cls._start_timestamp + 1001, value=3), - helpers.create_metric(name=name2, dimensions={'key1': 'value3', 'key2': 'value6', 'key3': 'value7'}, + helpers.create_metric(name=name2, + dimensions={'key1': 'value3', 'key2': 'value6', 'key3': 'value7'}, timestamp=cls._start_timestamp + 2001, value=5), - helpers.create_metric(name=name2, dimensions={'key1': 'value4', 'key2': 'value6', 'key3': 'value8'}, + helpers.create_metric(name=name2, + dimensions={'key1': 'value4', 'key2': 'value6', 'key3': 'value8'}, timestamp=cls._start_timestamp + 3001, value=7), ] diff --git a/tox.ini b/tox.ini index 218e8e5..e739885 100644 --- a/tox.ini +++ b/tox.ini @@ -42,16 +42,11 @@ commands = commands = oslo_debug_helper {posargs} [flake8] -# TODO: ignored checks should be enabled in the future -# H201 no 'except:' at least use 'except Exception:' -# H302 import only modules -# H405 multi line docstring summary not separated with an empty line -ignore = F821,H201,H302,H405,E901,E226 # H106: Don’t put vim configuration in source files # H203: Use assertIs(Not)None to check for None enable-extensions=H106,H203 max-complexity = 50 -max-line-length = 120 +max-line-length = 100 builtins = _ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,tools,build show-source = True