Пример #1
0
    def test_set_base_options(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        ask_ori = msf_cfg.ask
        defaults = MacsyDefaults()
        resp = [
            "Yes",  # enter section ?
            "ordered",  # db_type
            "linear",  # replicon_topology
            "None",  # sequence_db
        ]
        g = (r for r in resp)

        def fake_ask(*args, **kwargs):
            return next(g)

        try:
            msf_cfg.ask = fake_ask
            with self.catch_io(out=True):
                msf_cfg.set_base_options(cp, defaults)
                stdout = sys.stdout.getvalue().strip()
            self.assertEqual(
                stdout,
                f"{msf_cfg.theme.SECTION}Configuring base options:{msf_cfg.theme.RESET}"
            )
            self.assertTrue(cp.has_section("base"))
            self.assertEqual(cp.get("base", "db_type"), "ordered")
            self.assertEqual(cp.get("base", "replicon_topology"), "linear")
            self.assertEqual(cp.get("base", "sequence_db"), "None")
        finally:
            msf_cfg.ask = ask_ori
Пример #2
0
    def test_set_general_options(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        ask_ori = msf_cfg.ask
        defaults = MacsyDefaults()
        resp = [
            "Yes",  # enter section ?
            'warning',  # log_level
            0,  # worker
            True  # mute
        ]
        g = (r for r in resp)

        def fake_ask(*args, **kwargs):
            return next(g)

        try:
            msf_cfg.ask = fake_ask
            with self.catch_io(out=True):
                msf_cfg.set_general_options(cp, defaults)
                stdout = sys.stdout.getvalue().strip()
            self.assertEqual(
                stdout,
                f"{msf_cfg.theme.SECTION}Configuring general options:{msf_cfg.theme.RESET}"
            )
            self.assertTrue(cp.has_section("general"))
            self.assertEqual(cp.get("general", "log_level"), "warning")
            self.assertEqual(cp.get("general", "worker"), "0")
            self.assertEqual(cp.get("general", "mute"), "True")
        finally:
            msf_cfg.ask = ask_ori
Пример #3
0
    def test_set_section_use_defaults(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        sec_name = "new_section"
        options = {
            'hmmer': {
                "question": "that is the question",
                "validator": msf_cfg.check_str,
                "default": "Yes",
                "explanation": ""
            }
        }
        defaults = MacsyDefaults(hmmer="Yes")

        with self.catch_io(out=True):
            msf_cfg.set_section(sec_name,
                                options,
                                cp,
                                defaults,
                                use_defaults=True)
            stdout = sys.stdout.getvalue().strip()
        self.assertTrue(cp.has_section(sec_name))
        self.assertFalse(cp.has_option(sec_name, 'hmmer'))

        self.assertEqual(
            stdout,
            f"{msf_cfg.theme.SECTION}Configuring new_section options:{msf_cfg.theme.RESET}"
        )
Пример #4
0
    def test_ask_default_is_sequence(self):
        msf_cfg.theme = msf_cfg.Theme()

        resp = msf_cfg.ask("Question",
                           msf_cfg.check_positive_int, [1, 2, 3],
                           sequence=True)
        self.assertEqual(resp, [1, 2, 3])
Пример #5
0
    def test_ask_use_default(self):
        msf_cfg.theme = msf_cfg.Theme()

        val = msf_cfg.ask("Question",
                          msf_cfg.check_bool,
                          "Yes",
                          expected=["Yes", "No"],
                          explanation="bla bla")
        self.assertTrue(val)
Пример #6
0
    def test_ask_bad_value(self):
        msf_cfg.theme = msf_cfg.Theme()

        with self.catch_io(out=True):
            with self.assertRaises(RuntimeError) as ctx:
                msf_cfg.ask("Question", msf_cfg.check_bool)
        self.assertEqual(
            str(ctx.exception),
            f'{msf_cfg.theme.ERROR}Too many error. Exiting{msf_cfg.theme.RESET}'
        )
Пример #7
0
    def test_set_path_options_with_system_models_dir(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        ask_ori = msf_cfg.ask
        defaults = MacsyDefaults()

        test_dir = os.path.dirname(__file__)
        parent = os.path.join(os.path.normpath(os.path.join(test_dir, '..')))

        resp = [
            "Yes",  # enter section ?
            [parent, test_dir],  # system_models_dir
            os.getcwd(),  # res_search_dir
            "res_search_suffix",  # res_search_suffix
            "res_extract_suffix",  # res_extract_suffix
            "profile_suffix"
        ]  # profile_suffix
        g = (r for r in resp)

        def fake_ask(*args, **kwargs):
            return next(g)

        try:
            msf_cfg.ask = fake_ask
            with self.catch_io(out=True):
                msf_cfg.set_path_options(cp, defaults)
                stdout = sys.stdout.getvalue().strip()
            self.assertEqual(
                stdout,
                f"{msf_cfg.theme.SECTION}Configuring directories options:{msf_cfg.theme.RESET}"
            )
            self.assertTrue(cp.has_section("directories"))
            self.maxDiff = None
            self.assertEqual(cp.get("directories", "system_models_dir"),
                             f"{parent}, {test_dir}")
            self.assertEqual(cp.get("directories", "res_search_dir"),
                             os.getcwd())
            self.assertEqual(cp.get("directories", "res_search_suffix"),
                             "res_search_suffix")
            self.assertEqual(cp.get("directories", "res_extract_suffix"),
                             "res_extract_suffix")
            self.assertEqual(cp.get("directories", "profile_suffix"),
                             "profile_suffix")
        finally:
            msf_cfg.ask = ask_ori
Пример #8
0
    def test_set_score_options(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        ask_ori = msf_cfg.ask
        defaults = MacsyDefaults()
        resp = [
            "Yes",  # enter section ?
            0.1,  # mandatory_weight
            0.2,  # accessory_weight
            0.3,  # exchangeable_weight
            0.4,  # redundancy_penalty
            0.5  # out_of_cluster_weight
        ]
        g = (r for r in resp)

        def fake_ask(*args, **kwargs):
            return next(g)

        try:
            msf_cfg.ask = fake_ask
            with self.catch_io(out=True):
                msf_cfg.set_score_options(cp, defaults)
                stdout = sys.stdout.getvalue().strip()
            self.assertEqual(
                stdout,
                f"{msf_cfg.theme.SECTION}Configuring score_opt options:{msf_cfg.theme.RESET}"
            )
            self.assertTrue(cp.has_section("score_opt"))
            self.assertEqual(cp.get("score_opt", "mandatory_weight"), "0.1")
            self.assertEqual(cp.get("score_opt", "accessory_weight"), "0.2")
            self.assertEqual(cp.get("score_opt", "exchangeable_weight"), "0.3")
            self.assertEqual(cp.get("score_opt", "redundancy_penalty"), "0.4")
            self.assertEqual(cp.get("score_opt", "out_of_cluster_weight"),
                             "0.5")
        finally:
            msf_cfg.ask = ask_ori
Пример #9
0
    def test_set_hmmer_options(self):
        msf_cfg.theme = msf_cfg.Theme()
        cp = msf_cfg.ConfigParserWithComments()
        ask_ori = msf_cfg.ask
        defaults = MacsyDefaults()
        resp = [
            "Yes",  # enter section ?
            defaults.hmmer,  # hmmer exe
            True,  # no_cut_ga the fake_ask do not perform casting
            0.002,  # e_value_search,
            0.003,  # i_evalue_sel,
            0.004  # coverage_profile
        ]
        g = (r for r in resp)

        def fake_ask(*args, **kwargs):
            return next(g)

        try:
            msf_cfg.ask = fake_ask
            with self.catch_io(out=True):
                msf_cfg.set_hmmer_options(cp, defaults)
                stdout = sys.stdout.getvalue().strip()
            self.assertEqual(
                stdout,
                f"{msf_cfg.theme.SECTION}Configuring hmmer options:{msf_cfg.theme.RESET}"
            )
            self.assertTrue(cp.has_section("hmmer"))
            self.assertFalse(cp.has_option("hmmer", "hmmer"))
            # all values are casted in str before inserting in ConfigParser
            self.assertEqual(cp.get("hmmer", "no_cut_ga"), 'True')
            self.assertEqual(cp.get("hmmer", "e_value_search"), '0.002')
            self.assertEqual(cp.get("hmmer", "i_evalue_sel"), '0.003')
            self.assertEqual(cp.get("hmmer", "coverage_profile"), '0.004')
        finally:
            msf_cfg.ask = ask_ori
Пример #10
0
    def test_ask(self):
        msf_cfg.theme = msf_cfg.Theme()

        resp = msf_cfg.ask("Question", msf_cfg.check_bool)
        self.assertTrue(resp)