diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0656bb11819c8e10bba8fc8886cb170fe10526db..3d226bd62342a7da4a088563627fb0c3f51cbead 100755 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -143,6 +143,8 @@ coverage: - pip3 install -r requirements-dev.txt script: - pwd + - mv .coverage.unit .coverage + - coverage report - coverage combine .coverage.unit .coverage.functional - coverage report -i - coverage html -i diff --git a/PanACoTA/utils_argparse.py b/PanACoTA/utils_argparse.py index f55c8b8ba56725e473b455347f4136e704091aec..e890ecda9d3f262ba2124a0523b04a8287bb323d 100644 --- a/PanACoTA/utils_argparse.py +++ b/PanACoTA/utils_argparse.py @@ -200,6 +200,8 @@ class Conf_all_parser(configparser.ConfigParser): path to configuration file readsec : list list of sections of the config file to read + clean_str : boolean + by default, remove " surrounding strings. If no need to do it, set this parameter to False Attributes ---------- @@ -209,7 +211,7 @@ class Conf_all_parser(configparser.ConfigParser): {section1: {param: value}, {section2: {param:value}}} """ - def __init__(self, conffile, readsec=[]): + def __init__(self, conffile, readsec=[], clean_str=True): super().__init__() # If there is a config file specified, but it does not exist -> exit with error message if conffile != "" and not os.path.isfile(conffile): @@ -229,7 +231,8 @@ class Conf_all_parser(configparser.ConfigParser): # If not, create empty section, and associate with empty dict if sec in dict(self): self.sec_dicts[sec] = dict(self[sec]) - self.clean_strings(sec) + if clean_str: + self.clean_strings(sec) else: self.sec_dicts[sec] = {} self.add_section(sec) diff --git a/test/test_unit/test_utils-argparse.py b/test/test_unit/test_utils-argparse.py index 29152dcbefbca98073a0fdc0d0d63d1e7596f66e..8fd6e34928f0b45d401eb1ecf27647f12cdc7245 100644 --- a/test/test_unit/test_utils-argparse.py +++ b/test/test_unit/test_utils-argparse.py @@ -271,6 +271,22 @@ def test_conf_parser_init(): "sec4": {}} # But sec4 dict is empty (no param given in configfile) +def test_conf_parser_clean_str(capsys): + """ + Check that surounding "" are removed + """ + cfg_file = os.path.join("test", "data", "utils", "configfile-str.ini") + c = autils.Conf_all_parser(cfg_file, ["sec2", "sec_bool"]) + assert c.get_section_dict("sec2") == {"param2": "", "myval": "parameter", + 'param3': "myparameter", + "param1": "3"} + assert c.get_section_dict("sec_bool") == {"bool num_false": "0", "bool_num_true": "1", + "bool_f": "off", "bool_t": "ON", "bool_n": "no", + "bool_y": "YES", + "bool_false": "FalSe", "bool_true": "tRUE", + "param1": "3", "param2": "10"} + + def test_conf_parser_get_section(capsys): """ Test get dict of values for a given section