From 9c718ac372d16a197e428f5c9b65cdf76005ce12 Mon Sep 17 00:00:00 2001 From: Lukáš Růžička Date: Feb 15 2019 12:52:55 +0000 Subject: Rewrite the module_list() method The method now returns a dictionary with module names as keys and their streams as values. No matter how many times the module stream appear in the DNF output, they only will be in the list once. --- diff --git a/modular_functions.py b/modular_functions.py index 876f414..276e190 100755 --- a/modular_functions.py +++ b/modular_functions.py @@ -24,7 +24,7 @@ import sys class TestSuite: def __init__(self, test='all'): self.test = test - self.modlist = [] + self.modlist = {} self.results = {} self.outputs = {} logging.info('The test suite has been initialized.') @@ -75,38 +75,35 @@ class TestSuite: strip = [re.split(r'\s\s+', x.strip()) for x in processed] # Let us parse the DNF command output and create module dictionaries with all required info, that is name, streams, profiles - for line in strip: # Gets the modules lines from the output into a list of modules - module = {} + modulelist = {} + for line in strip: # Gets the modules lines from the output into a list of modules + module = {} + modName = line[0] try: - module['name'] = line[0] module['stream'] = line[1].split('[')[0].strip() module['profile'] = line[2].split('[')[0].strip() module['info'] = line[3] except IndexError: logging.info(f"The {line[0]} module probably does not meet standard criteria. Check 'dnf module list'. Skipping tests for broken validity.") - module['name'] = line[0] module['stream'] = 'NA' module['profile'] = 'NA' module['info'] = 'NA' - if module not in self.modlist: - self.modlist.append(module) + if modName not in modulelist.keys(): #If this is first occurence + modulelist[modName] = [module] + else: # If this is another occurence of same module with different streams. + if module not in modulelist[modName]: + modulelist[modName].append(module) + else: + pass + self.modlist = modulelist self.store_results('dnf module list', result) logging.info('The "dnf module list" operation was succesful.') - return self.modlist # Return a list of modules with the following form: name, [streams], [profiles], info - + return self.modlist + def module_info(self, moduleName): """Returns a dictionary with streams as keys and profiles as values.""" - self.module_list() - info = {} - searchedMod = [x for x in self.modlist if x['name'] == moduleName] - for record in searchedMod: - strName = record['stream'] - if strName not in info.keys(): - rawProfile = record['profile'] - cleanProfile = [] - for p in rawProfile.split(','): - cleanProfile.append(p.strip()) - info[strName] = cleanProfile + modules = self.module_list() + info = modules[moduleName] return info @@ -361,9 +358,10 @@ class ModuleTest: modules = self.suite.module_list() print(f"{len(self.suite.modlist)} modules will be tested.") for mod in modules: - #info = self.suite.module_info(mod) - #name = mod['name'] - print(f'Testing module {mod}.') + name = mod['name'] + info = self.suite.module_info(name) + print(f"Testing module {name}.") + print(info.keys()) def run_test(self, module, fail, newer, stream, profile): self.newer = newer