From 318321a2cfd8ff33b51983b7f65cb3c20967d6c2 Mon Sep 17 00:00:00 2001
From: asetGem <amandine.perrin@pasteur.fr>
Date: Mon, 2 Aug 2021 10:20:35 +0200
Subject: [PATCH] get report of unit tests coverage

---
 .gitlab-ci.yml                        |  2 ++
 PanACoTA/utils_argparse.py            |  7 +++++--
 test/test_unit/test_utils-argparse.py | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 2 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 0656bb11..3d226bd6 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 f55c8b8b..e890ecda 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 29152dcb..8fd6e349 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
-- 
GitLab