diff --git a/biobb_common/configuration/settings.py b/biobb_common/configuration/settings.py index a4549a3..70c70e3 100644 --- a/biobb_common/configuration/settings.py +++ b/biobb_common/configuration/settings.py @@ -199,183 +199,7 @@ def get_prop_dic(self, prefix: str = "", global_log: Optional[logging.Logger] = return prop_dic - # def get_prop_dic(self, prefix: Optional[str] = None, global_log: Optional[logging.Logger] = None) -> Dict[str, Any]: - # """get_prop_dic() returns the properties dictionary where keys are the - # step names in the configuration YAML file and every value contains another - # nested dictionary containing the keys and values of each step properties section. - # All the paths in the system section are copied in each nested dictionary. - # For each nested dictionary the following keys are added: - # | **path** (*str*): Absolute path to the step working dir. - # | **step** (*str*): Name of the step. - # | **prefix** (*str*): Prefix if provided. - # | **global_log** (*Logger object*): Log from the main workflow. - # | **restart** (*bool*): Restart from previous execution. - # | **remove_tmp** (*bool*): Remove temporal files. - # | **sandbox_path** (*str*) - ("./") Parent path to the sandbox directory. - - # Args: - # prefix (str): Prefix if provided. - # global_log (:obj:Logger): Log from the main workflow. - - # Returns: - # dict: Dictionary of properties. - # """ - - # prop_dic: Dict[str, Any] = dict() - # prefix = "" if prefix is None else prefix.strip() - - # # There is no step - # if "paths" in self.properties or "properties" in self.properties: - # prop_dic = dict() - # prop_dic["path"] = str(Path(self.properties["working_dir_path"]).joinpath(prefix)) - # prop_dic["step"] = None - # prop_dic["prefix"] = prefix - # prop_dic["global_log"] = global_log - # prop_dic["working_dir_path"] = self.properties.get("working_dir_path") - # prop_dic["restart"] = self.properties.get("restart", False) - # prop_dic["remove_tmp"] = self.properties.get("remove_tmp", True) - # prop_dic["sandbox_path"] = self.properties.get("sandbox_path", Path.cwd()) - - # if "properties" in self.properties and isinstance( - # self.properties["properties"], dict - # ): - # prop_dic.update(self.properties["properties"].copy()) - # if self.properties.get("", None): - # prop_dic[""] = self.properties[""] - # # There is step name - # else: - # for key in self.properties: - # if isinstance(self.properties[key], dict): - # if ( - # "paths" in self.properties[key] - # or "properties" in self.properties[key] - # ): - # prop_dic[key] = dict() - # prop_dic[key]["path"] = str( - # Path(self.properties["working_dir_path"]).joinpath( - # prefix, key - # ) - # ) - # prop_dic[key]["step"] = key - # prop_dic[key]["prefix"] = prefix - # prop_dic[key]["global_log"] = global_log - # prop_dic[key]["working_dir_path"] = self.properties.get( - # "working_dir_path" - # ) - # prop_dic[key][ - # "can_write_console_log" - # ] = self.properties.get("can_write_console_log", True) - # prop_dic[key]["restart"] = self.properties.get( - # "restart", False - # ) - # prop_dic[key]["remove_tmp"] = self.properties.get( - # "remove_tmp", True - # ) - - # if ("properties" in self.properties[key]) and isinstance( - # self.properties[key]["properties"], dict - # ): - # if self.properties.get("", None): - # prop_dic[key][""] = self.properties[ - # "" - # ] - # prop_dic[key][ - # "can_write_console_log" - # ] = self.properties.get("can_write_console_log", True) - # prop_dic[key].update(self.properties[key]["properties"].copy()) - - # # There is no step name and there is no properties or paths key: return input - # if not prop_dic: - # prop_dic = dict() - # prop_dic.update(self.properties) - # prop_dic["path"] = str( - # Path(self.properties["working_dir_path"]).joinpath(prefix) - # ) - # prop_dic["step"] = None - # prop_dic["prefix"] = prefix - # prop_dic["global_log"] = global_log - # prop_dic["working_dir_path"] = self.properties.get("working_dir_path") - # prop_dic["can_write_console_log"] = self.properties.get( - # "can_write_console_log", True - # ) - # prop_dic["restart"] = self.properties.get("restart", False) - # prop_dic["remove_tmp"] = self.properties.get("remove_tmp", True) - - # return prop_dic - - def get_paths_dic(self, prefix: Optional[str] = None) -> dict: - """get_paths_dic() returns the paths dictionary where keys are the - step names in the configuration YAML file and every value contains another - nested dictionary containing the keys and values of each step paths section. - All the paths starting with 'dependency' are resolved. If the path starts - with the string 'file:' nothing is done, however if the path starts with - any other string path is prefixed with the absolute step path. - - Args: - prefix (str): Prefix if provided. - - Returns: - dict: Dictionary of paths. - """ - prop_dic = dict() - prefix = "" if prefix is None else prefix.strip() - # Filtering just paths - # Properties without step name - if "paths" in self.properties: - step = False - prop_dic = self.properties["paths"].copy() - - # Properties with name - else: - step = True - - for key in self.properties: - if isinstance(self.properties[key], dict): - if "paths" in self.properties[key]: - prop_dic[key] = self.properties[key]["paths"].copy() - else: - prop_dic[key] = {} - - # Solving dependencies and adding workflow and step path - # Properties without step name: Do not solving dependencies - if not step: - for key2, value in prop_dic.items(): - if isinstance(value, str) and value.startswith("file:"): - prop_dic[key2] = value.split(":")[1] - else: - prop_dic[key2] = str( - Path(self.properties["working_dir_path"]).joinpath( - prefix, value - ) - ) - - # Properties with step name - else: - - for key in prop_dic: - for key2, value in prop_dic[key].items(): - if isinstance(value, str) and value.startswith("dependency"): - dependency_step = value.split("/")[1] - while isinstance(value, str) and value.startswith("dependency"): - dependency_step = value.split("/")[1] - value = prop_dic[value.split("/")[1]][value.split("/")[2]] - prop_dic[key][key2] = str( - Path(self.properties["working_dir_path"]).joinpath( - prefix, dependency_step, value - ) - ) - elif isinstance(value, str) and value.startswith("file:"): - prop_dic[key][key2] = value.split(":")[1] - else: - prop_dic[key][key2] = str( - Path(self.properties["working_dir_path"]).joinpath( - prefix, key, value - ) - ) - - return prop_dic - - def _get_paths(self, prefix: str = "") -> Dict[str, Any]: + def get_paths_dic(self, prefix: str = "") -> Dict[str, Any]: paths_dic: Dict[str, Any] = dict() for key in self.properties: if key in ["global_properties", "paths", "properties", "tool"]: @@ -394,18 +218,28 @@ def _get_step_paths(self, key: str = "", prefix: str = "") -> Dict[str, Any]: else: paths_dic = self.properties.get("paths", {}) for file_key, path_value in paths_dic.items(): - step_paths_dic[file_key] = self._join_paths(prefix=prefix, value=self._solve_dependency(paths_dic, key, path_value)) + if path_value.startswith("file:"): + step_paths_dic[file_key] = path_value.replace("file:", "") + continue + step_paths_dic[file_key] = self._join_paths(prefix=prefix, value=self._solve_dependency(key, path_value)) return step_paths_dic - def _solve_dependency(self, paths_dic: Dict[str, Any], step, dependency_str: str) -> str: + def _solve_dependency(self, step, dependency_str: str) -> str: """_solve_dependency() solves the dependency of a path in the configuration file. """ dependency_tokens = dependency_str.strip().split("/") if dependency_tokens[0] != "dependency": return str(Path(step).joinpath(dependency_str)) - return str(Path(dependency_tokens[1]).joinpath(paths_dic[dependency_tokens[1]][dependency_tokens[2]])) + + if not step: + raise Exception("Step name is required to solve dependency") + + return str(Path(dependency_tokens[1]).joinpath(self.properties.get(dependency_tokens[1], {}).get('paths', {}).get(dependency_tokens[2], ""))) def _join_paths(self, prefix: str = "", value: str = "") -> str: """_join_working_dir_path() returns the absolute path to the step working dir. """ + if value.startswith("/"): + value = value[1:] + return str(Path(self.working_dir_path).joinpath(prefix, value)) diff --git a/biobb_common/tools/test_fixtures.py b/biobb_common/tools/test_fixtures.py index 31ec457..fbfb665 100644 --- a/biobb_common/tools/test_fixtures.py +++ b/biobb_common/tools/test_fixtures.py @@ -3,7 +3,6 @@ import os import pickle import typing -from pprint import pprint from typing import Optional, Union, List, Dict from pathlib import Path import sys @@ -56,7 +55,7 @@ def test_teardown(test_object): test_object (:obj:`test`): The test object. """ unitests_path = Path(test_object.properties['path']).resolve().parent - pprint(f"\nRemoving: {unitests_path}") + print(f"\nRemoving: {unitests_path}") shutil.rmtree(unitests_path) @@ -81,19 +80,19 @@ def not_empty(file_path: str) -> bool: Returns: bool: True if **file_path** exists and is not empty. """ - pprint("Checking if empty file: "+file_path) + print("Checking if empty file: "+file_path) return Path(file_path).is_file() and Path(file_path).stat().st_size > 0 def compare_hash(file_a: str, file_b: str) -> bool: """Compute and compare the hashes of two files""" - pprint("Comparing: ") - pprint(" File_A: "+file_a) - pprint(" File_B: "+file_b) + print("Comparing: ") + print(" File_A: "+file_a) + print(" File_B: "+file_b) file_a_hash = hashlib.sha256(open(file_a, 'rb').read()).digest() file_b_hash = hashlib.sha256(open(file_b, 'rb').read()).digest() - pprint(" File_A hash: "+str(file_a_hash)) - pprint(" File_B hash: "+str(file_b_hash)) + print(" File_A hash: "+str(file_a_hash)) + print(" File_B hash: "+str(file_b_hash)) return file_a_hash == file_b_hash @@ -141,9 +140,9 @@ def equal(file_a: str, file_b: str, ignore_list: Optional[typing.List[typing.Uni def compare_line_by_line(file_a: str, file_b: str, ignore_list: typing.List[typing.Union[str, int]]) -> bool: - pprint(f"Comparing ignoring lines containing this words: {ignore_list}") - pprint(" FILE_A: "+file_a) - pprint(" FILE_B: "+file_b) + print(f"Comparing ignoring lines containing this words: {ignore_list}") + print(" FILE_A: "+file_a) + print(" FILE_B: "+file_b) with open(file_a) as fa, open(file_b) as fb: for index, (line_a, line_b) in enumerate(zip(fa, fb)): if index in ignore_list or any(word in line_a for word in ignore_list if isinstance(word, str)): @@ -160,12 +159,12 @@ def equal_txt(file_a: str, file_b: str) -> bool: def compare_zip(zip_a: str, zip_b: str) -> bool: """ Compare zip files """ - pprint("This is a ZIP comparison!") - pprint("Unzipping:") - pprint("Creating a unique_dir for: %s" % zip_a) + print("This is a ZIP comparison!") + print("Unzipping:") + print("Creating a unique_dir for: %s" % zip_a) zip_a_dir = fu.create_unique_dir() zip_a_list = fu.unzip_list(zip_a, dest_dir=zip_a_dir) - pprint("Creating a unique_dir for: %s" % zip_b) + print("Creating a unique_dir for: %s" % zip_b) zip_b_dir = fu.create_unique_dir() zip_b_list = fu.unzip_list(zip_b, dest_dir=zip_b_dir) @@ -182,15 +181,15 @@ def compare_zip(zip_a: str, zip_b: str) -> bool: def compare_pdb(pdb_a: str, pdb_b: str, rmsd_cutoff: int = 1, remove_hetatm: bool = True, remove_hydrogen: bool = True, **kwargs): """ Compare pdb files """ - pprint("Checking RMSD between:") - pprint(" PDB_A: "+pdb_a) - pprint(" PDB_B: "+pdb_b) + print("Checking RMSD between:") + print(" PDB_A: "+pdb_a) + print(" PDB_B: "+pdb_b) pdb_parser = Bio.PDB.PDBParser(PERMISSIVE=True, QUIET=True) st_a = pdb_parser.get_structure("st_a", pdb_a)[0] st_b = pdb_parser.get_structure("st_b", pdb_b)[0] if remove_hetatm: - pprint(" Ignoring HETAMT in RMSD") + print(" Ignoring HETAMT in RMSD") residues_a = [list(res.get_atoms()) for res in st_a.get_residues() if not res.id[0].startswith('H_')] residues_b = [list(res.get_atoms()) for res in st_b.get_residues() if not res.id[0].startswith('H_')] atoms_a = [atom for residue in residues_a for atom in residue] @@ -200,26 +199,26 @@ def compare_pdb(pdb_a: str, pdb_b: str, rmsd_cutoff: int = 1, remove_hetatm: boo atoms_b = st_b.get_atoms() if remove_hydrogen: - pprint(" Ignoring Hydrogen atoms in RMSD") + print(" Ignoring Hydrogen atoms in RMSD") atoms_a = [atom for atom in atoms_a if not atom.get_name().startswith('H')] atoms_b = [atom for atom in atoms_b if not atom.get_name().startswith('H')] - pprint(" Atoms ALIGNED in PDB_A: "+str(len(atoms_a))) - pprint(" Atoms ALIGNED in PDB_B: "+str(len(atoms_b))) + print(" Atoms ALIGNED in PDB_A: "+str(len(atoms_a))) + print(" Atoms ALIGNED in PDB_B: "+str(len(atoms_b))) super_imposer = Bio.PDB.Superimposer() super_imposer.set_atoms(atoms_a, atoms_b) super_imposer.apply(atoms_b) super_imposer_rms = super_imposer.rms if super_imposer.rms is not None else float('inf') - pprint(' RMS: '+str(super_imposer_rms)) - pprint(' RMS_CUTOFF: '+str(rmsd_cutoff)) + print(' RMS: '+str(super_imposer_rms)) + print(' RMS_CUTOFF: '+str(rmsd_cutoff)) return super_imposer_rms < rmsd_cutoff def compare_top_itp(file_a: str, file_b: str) -> bool: """ Compare top/itp files """ - pprint("Comparing TOP/ITP:") - pprint(" FILE_A: "+file_a) - pprint(" FILE_B: "+file_b) + print("Comparing TOP/ITP:") + print(" FILE_A: "+file_a) + print(" FILE_B: "+file_b) with codecs.open(file_a, 'r', encoding='utf-8', errors='ignore') as f_a: next(f_a) with codecs.open(file_b, 'r', encoding='utf-8', errors='ignore') as f_b: @@ -229,9 +228,9 @@ def compare_top_itp(file_a: str, file_b: str) -> bool: def compare_ignore_first(file_a: str, file_b: str) -> bool: """ Compare two files ignoring the first line """ - pprint("Comparing ignoring first line of both files:") - pprint(" FILE_A: "+file_a) - pprint(" FILE_B: "+file_b) + print("Comparing ignoring first line of both files:") + print(" FILE_A: "+file_a) + print(" FILE_B: "+file_b) with open(file_a) as f_a: next(f_a) with open(file_b) as f_b: @@ -241,26 +240,26 @@ def compare_ignore_first(file_a: str, file_b: str) -> bool: def compare_size(file_a: str, file_b: str, percent_tolerance: float = 1.0) -> bool: """ Compare two files using size """ - pprint("Comparing size of both files:") - pprint(f" FILE_A: {file_a}") - pprint(f" FILE_B: {file_b}") + print("Comparing size of both files:") + print(f" FILE_A: {file_a}") + print(f" FILE_B: {file_b}") size_a = Path(file_a).stat().st_size size_b = Path(file_b).stat().st_size average_size = (size_a + size_b) / 2 tolerance = average_size * percent_tolerance / 100 tolerance_low = average_size - tolerance tolerance_high = average_size + tolerance - pprint(f" SIZE_A: {size_a} bytes") - pprint(f" SIZE_B: {size_b} bytes") - pprint(f" TOLERANCE: {percent_tolerance}%, Low: {tolerance_low} bytes, High: {tolerance_high} bytes") + print(f" SIZE_A: {size_a} bytes") + print(f" SIZE_B: {size_b} bytes") + print(f" TOLERANCE: {percent_tolerance}%, Low: {tolerance_low} bytes, High: {tolerance_high} bytes") return (tolerance_low <= size_a <= tolerance_high) and (tolerance_low <= size_b <= tolerance_high) def compare_xvg(file_a: str, file_b: str, percent_tolerance: float = 1.0) -> bool: """ Compare two files using size """ - pprint("Comparing size of both files:") - pprint(f" FILE_A: {file_a}") - pprint(f" FILE_B: {file_b}") + print("Comparing size of both files:") + print(f" FILE_A: {file_a}") + print(f" FILE_B: {file_b}") arrays_tuple_a = np.loadtxt(file_a, comments="@", unpack=True) arrays_tuple_b = np.loadtxt(file_b, comments="@", unpack=True) for array_a, array_b in zip(arrays_tuple_a, arrays_tuple_b): @@ -274,22 +273,22 @@ def compare_images(file_a: str, file_b: str, percent_tolerance: float = 1.0) -> from PIL import Image # type: ignore import imagehash except ImportError: - pprint("To compare images, please install the following packages: Pillow, imagehash") + print("To compare images, please install the following packages: Pillow, imagehash") return False """ Compare two files using size """ - pprint("Comparing images of both files:") - pprint(f" IMAGE_A: {file_a}") - pprint(f" IMAGE_B: {file_b}") + print("Comparing images of both files:") + print(f" IMAGE_A: {file_a}") + print(f" IMAGE_B: {file_b}") hash_a = imagehash.average_hash(Image.open(file_a)) hash_b = imagehash.average_hash(Image.open(file_b)) tolerance = (len(hash_a) + len(hash_b)) / 2 * percent_tolerance / 100 if tolerance < 1: tolerance = 1 difference = hash_a - hash_b - pprint(f" IMAGE_A HASH: {hash_a} SIZE: {len(hash_a)} bits") - pprint(f" IMAGE_B HASH: {hash_b} SIZE: {len(hash_b)} bits") - pprint(f" TOLERANCE: {percent_tolerance}%, ABS TOLERANCE: {tolerance} bits, DIFFERENCE: {difference} bits") + print(f" IMAGE_A HASH: {hash_a} SIZE: {len(hash_a)} bits") + print(f" IMAGE_B HASH: {hash_b} SIZE: {len(hash_b)} bits") + print(f" TOLERANCE: {percent_tolerance}%, ABS TOLERANCE: {tolerance} bits, DIFFERENCE: {difference} bits") if difference > tolerance: return False return True @@ -297,26 +296,34 @@ def compare_images(file_a: str, file_b: str, percent_tolerance: float = 1.0) -> def compare_object_pickle(python_object: typing.Any, pickle_file_path: Union[str, Path], **kwargs) -> bool: """ Compare a python object with a pickle file """ - pprint(f"Loading pickle file: {pickle_file_path}") + print(f"Loading pickle file: {pickle_file_path}") with open(pickle_file_path, 'rb') as f: pickle_object = pickle.load(f) - pprint(f" OBJECT: {python_object}") - pprint(f" EXPECTED OBJECT: {pickle_object}") # Special case for dictionaries if isinstance(python_object, dict) and isinstance(pickle_object, dict): - differences = compare_dictionaries(python_object, pickle_object, ignore_keys=kwargs.get('ignore_keys', []), compare_values=kwargs.get('compare_values', True)) + differences = compare_dictionaries(python_object, pickle_object, ignore_keys=kwargs.get('ignore_keys', []), compare_values=kwargs.get('compare_values', True), ignore_substring=kwargs.get('ignore_substring', "")) if differences: - pprint("Differences found:") + print(50*'*') + print("OBJECT:") + print(python_object) + print(50*'*') + print() + print(50*'*') + print("EXPECTED OBJECT:") + print(pickle_object) + print(50*'*') + + print("Differences found:") for difference in differences: - pprint(f" {difference}") + print(f" {difference}") return False return True return python_object == pickle_object -def compare_dictionaries(dict1: Dict, dict2: Dict, path: str = "", ignore_keys: Optional[List[str]] = None, compare_values: bool = True) -> List[str]: +def compare_dictionaries(dict1: Dict, dict2: Dict, path: str = "", ignore_keys: Optional[List[str]] = None, compare_values: bool = True, ignore_substring: str = "") -> List[str]: """Compare two dictionaries and print only the differences, ignoring specified keys.""" if ignore_keys is None: ignore_keys = [] @@ -338,9 +345,14 @@ def compare_dictionaries(dict1: Dict, dict2: Dict, path: str = "", ignore_keys: value2 = dict2[key] if isinstance(value1, dict) and isinstance(value2, dict): # Recursively compare nested dictionaries - nested_differences = compare_dictionaries(value1, value2, path + key + ".", ignore_keys, compare_values) + nested_differences = compare_dictionaries(value1, value2, path + key + ".", ignore_keys, compare_values, ignore_substring) differences.extend(nested_differences) - elif value1 != value2 and compare_values: - differences.append(f"Difference at '{path + key}': dict1 has {value1}, dict2 has {value2}") + elif (value1 != value2) and compare_values: + if ignore_substring: + if (not str(value1).endswith(str(value2).replace(ignore_substring, ""))) and (not str(value2).endswith(str(value1).replace(ignore_substring, ""))): + differences.append(f"Difference at '{path + key}': dict1 has {value1}, dict2 has {value2}") + + else: + differences.append(f"Difference at '{path + key}': dict1 has {value1}, dict2 has {value2}") return differences diff --git a/test/conf.yml b/test/conf.yml index 1e234d1..f18fd6a 100644 --- a/test/conf.yml +++ b/test/conf.yml @@ -9,11 +9,17 @@ confreader: config_empty: file:test_data_dir/configuration/config_empty.yml config_nostep_globals: file:test_data_dir/configuration/config_nostep_globals.yml config_nostep: file:test_data_dir/configuration/config_nostep.yml + ref_config_complete_pkl: file:test_reference_dir/configuration/config_complete.pkl ref_config_empty_pkl: file:test_reference_dir/configuration/config_empty.pkl ref_config_nostep_globals_pkl: file:test_reference_dir/configuration/config_nostep_globals.pkl ref_config_nostep_pkl: file:test_reference_dir/configuration/config_nostep.pkl + ref_config_complete_paths_pkl: file:test_reference_dir/configuration/config_complete_paths.pkl + ref_config_empty_paths_pkl: file:test_reference_dir/configuration/config_empty_paths.pkl + ref_config_nostep_globals_paths_pkl: file:test_reference_dir/configuration/config_nostep_globals_paths.pkl + ref_config_nostep_paths_pkl: file:test_reference_dir/configuration/config_nostep_paths.pkl + properties: remove_tmp: False diff --git a/test/data/configuration/config_nostep.yml b/test/data/configuration/config_nostep.yml index 9da9664..1f8d785 100644 --- a/test/data/configuration/config_nostep.yml +++ b/test/data/configuration/config_nostep.yml @@ -1,6 +1,6 @@ tool: pdb2gmx paths: - input_pdb_path: dependency/step4_fix_side_chain/output_pdb_path + input_pdb_path: path/to/output_pdb_path output_gro_path: pdb2gmx.gro output_top_zip_path: pdb2gmx_top.zip properties: diff --git a/test/data/configuration/config_nostep_globals.yml b/test/data/configuration/config_nostep_globals.yml index 8d133e7..e4f2d0a 100644 --- a/test/data/configuration/config_nostep_globals.yml +++ b/test/data/configuration/config_nostep_globals.yml @@ -5,7 +5,7 @@ global_properties: tool: pdb2gmx paths: - input_pdb_path: dependency/step4_fix_side_chain/output_pdb_path + input_pdb_path: path/to/output_pdb_path output_gro_path: pdb2gmx.gro output_top_zip_path: pdb2gmx_top.zip properties: diff --git a/test/reference/configuration/config_complete_paths.pkl b/test/reference/configuration/config_complete_paths.pkl index b6b05ba..a1f4e06 100644 Binary files a/test/reference/configuration/config_complete_paths.pkl and b/test/reference/configuration/config_complete_paths.pkl differ diff --git a/test/reference/configuration/config_nostep_globals_paths.pkl b/test/reference/configuration/config_nostep_globals_paths.pkl index f7e060a..2e7dafc 100644 Binary files a/test/reference/configuration/config_nostep_globals_paths.pkl and b/test/reference/configuration/config_nostep_globals_paths.pkl differ diff --git a/test/reference/configuration/config_nostep_paths.pkl b/test/reference/configuration/config_nostep_paths.pkl index f7e060a..9128381 100644 Binary files a/test/reference/configuration/config_nostep_paths.pkl and b/test/reference/configuration/config_nostep_paths.pkl differ diff --git a/test/unitests/test_configuration/test_confreader.py b/test/unitests/test_configuration/test_confreader.py index 01552c7..b8a083f 100644 --- a/test/unitests/test_configuration/test_confreader.py +++ b/test/unitests/test_configuration/test_confreader.py @@ -11,15 +11,14 @@ def teardown_class(self): # pass fx.test_teardown(self) - def test_confreader(self): - conf = ConfReader(self.paths['config_complete']) - assert fx.compare_object_pickle(conf.get_prop_dic(), self.paths['ref_config_complete_pkl'], ignore_keys=['path', 'working_dir_path', 'sandbox_path']) + def test_confreader_properties(self): + print() # Add a new line for better readability in the console + for file_name in ['config_complete', 'config_empty', 'config_nostep', 'config_nostep_globals']: + conf = ConfReader(self.paths[file_name]) + assert fx.compare_object_pickle(conf.get_prop_dic(), self.paths[f'ref_{file_name}_pkl'], ignore_keys=['path', 'working_dir_path', 'sandbox_path']) - conf = ConfReader(self.paths['config_empty']) - assert fx.compare_object_pickle(conf.get_prop_dic(), self.paths['ref_config_empty_pkl'], ignore_keys=['path', 'working_dir_path', 'sandbox_path']) - - conf = ConfReader(self.paths['config_nostep']) - assert fx.compare_object_pickle(conf.get_prop_dic(), self.paths['ref_config_nostep_pkl'], ignore_keys=['path', 'working_dir_path', 'sandbox_path']) - - conf = ConfReader(self.paths['config_nostep_globals']) - assert fx.compare_object_pickle(conf.get_prop_dic(), self.paths['ref_config_nostep_globals_pkl'], ignore_keys=['path', 'working_dir_path', 'sandbox_path']) + def test_confreader_paths(self): + print() # Add a new line for better readability in the console + for file_name in ['config_complete', 'config_empty', 'config_nostep', 'config_nostep_globals']: + conf = ConfReader(self.paths[file_name]) + assert fx.compare_object_pickle(conf.get_paths_dic(), self.paths[f'ref_{file_name}_paths_pkl'], ignore_keys=['working_dir_path', 'sandbox_path'], ignore_substring='/Users/pau/projects/biobb_common/')