From e421ee19ae289aa05fa55216bbdf31f59fb6eee1 Mon Sep 17 00:00:00 2001 From: Arif Ali Date: Fri, 9 Feb 2024 00:07:16 +0000 Subject: [pep8][tests] Update flake8 styling Related: Discussion #3513 Signed-off-by: Arif Ali --- plugins_overview.py | 35 +++++++++------ tests/unittests/archive_tests.py | 3 +- tests/unittests/cleaner_tests.py | 82 +++++++++++++++++++++++++----------- tests/unittests/conformance_tests.py | 9 ++-- tests/unittests/plugin_tests.py | 15 +++++-- tests/unittests/policy_tests.py | 1 - tests/unittests/report_tests.py | 4 +- 7 files changed, 101 insertions(+), 48 deletions(-) diff --git a/plugins_overview.py b/plugins_overview.py index 46bcbf5a..d847548c 100644 --- a/plugins_overview.py +++ b/plugins_overview.py @@ -8,7 +8,7 @@ # - list of paths it forbits to collect (add_forbidden_path) # - list of commands it calls (add_cmd_output) # -# Output of the script: +# Output of the script: # - a JSON object with plugins in keys # - or CSV format in case "csv" cmdline is provided # @@ -29,9 +29,11 @@ PLUGDIR = 'sos/report/plugins' plugs_data = {} # the map of all plugins data to collect plugcontent = '' # content of plugin file just being processed + # method to parse an item of a_s_c/a_c_o/.. methods # we work on an assumption the item is a string quoted by \" or optionally -# by \'. If we detect at least 2 such chars in the item, take what is between those. +# by \'. If we detect at least 2 such chars in the item, take what is between +# those. def add_valid_item(dest, item): for qoutemark in "\"\'": split = item.split(qoutemark) @@ -39,13 +41,14 @@ def add_valid_item(dest, item): dest.append(split[1]) return -# method to find in `plugcontent` all items of given method (a_c_s/a_c_o/..) split -# by comma; add each valid item to the `dest` list + +# method to find in `plugcontent` all items of given method (a_c_s/a_c_o/..) +# split by comma; add each valid item to the `dest` list def add_all_items(method, dest, wrapopen='\(', wrapclose='\)'): regexp = "%s%s(.*?)%s" % (method, wrapopen, wrapclose) for match in re.findall(regexp, plugcontent, flags=re.MULTILINE|re.DOTALL): # tuple of distros ended by either (class|from|import) - if isinstance(match,tuple): + if isinstance(match, tuple): for item in list(match): if item not in ['class', 'from', 'import']: for it in item.split(','): @@ -63,7 +66,8 @@ def add_all_items(method, dest, wrapopen='\(', wrapclose='\)'): else: add_valid_item(dest, match) -# main body: traverse report's plugins directory and for each plugin, grep for + +# main body: traverse report's plugins directory and for each plugin, grep for # add_copy_spec / add_forbidden_path / add_cmd_output there for plugfile in sorted(os.listdir(PLUGDIR)): # ignore non-py files and __init__.py @@ -73,7 +77,8 @@ for plugfile in sorted(os.listdir(PLUGDIR)): # if plugname != 'bcache': # continue plugs_data[plugname] = { - 'sourcecode': 'https://github.com/sosreport/sos/blob/main/sos/report/plugins/%s.py' % plugname, + 'sourcecode': 'https://github.com/sosreport/sos/blob/' + f'main/sos/report/plugins/{plugname}.py', 'distros': [], 'profiles': [], 'packages': [], @@ -84,8 +89,13 @@ for plugfile in sorted(os.listdir(PLUGDIR)): 'journals': [], 'env': [], } - plugcontent = open(os.path.join(PLUGDIR, plugfile)).read().replace('\n','') - add_all_items("from sos.report.plugins import ", plugs_data[plugname]['distros'], wrapopen='', wrapclose='(class|from|import)') + plugcontent = open(os.path.join(PLUGDIR, plugfile)).read().replace('\n', '') + add_all_items( + "from sos.report.plugins import ", + plugs_data[plugname]['distros'], + wrapopen='', + wrapclose='(class|from|import)' + ) add_all_items("profiles = ", plugs_data[plugname]['profiles'], wrapopen='') add_all_items("packages = ", plugs_data[plugname]['packages'], wrapopen='') add_all_items("add_copy_spec", plugs_data[plugname]['copyspecs']) @@ -98,7 +108,8 @@ for plugfile in sorted(os.listdir(PLUGDIR)): # print output; if "csv" is cmdline argument, print in CSV format, else JSON if (len(sys.argv) > 1) and (sys.argv[1] == "csv"): - print("plugin;url;distros;profiles;packages;copyspecs;forbidden;commands;service_status;journals;env_vars") + print("plugin;url;distros;profiles;packages;copyspecs;forbidden;commands;" + "service_status;journals;env_vars") for plugname in plugs_data.keys(): plugin = plugs_data[plugname] # determine max number of lines - usually "max(len(copyspec),len(commands))" @@ -109,10 +120,10 @@ if (len(sys.argv) > 1) and (sys.argv[1] == "csv"): for key in plugkeys: maxline = max(maxline, len(plugin[key])) for line in range(maxline): - out = ";" if line>0 else ("%s;%s" % (plugname, plugin['sourcecode'])) + out = ";" if line > 0 else f"{plugname};{plugin['sourcecode']}" for key in plugkeys: out += ";" - if line