def test_config_file_2_dict(self): cfg = Config(self.defaults, self.parsed_args) res = cfg._config_file_2_dict(self.defaults, ['nimportnaoik']) self.assertDictEqual({}, res) cfg_file = self.find_data( os.path.join('conf_files', 'macsy_test_conf.conf')) res = cfg._config_file_2_dict(self.defaults, [cfg_file]) expected = { 'db_type': 'gembase', 'inter_gene_max_space': 'set_1/T2SS 2 set_1/Flagellum 4', 'min_mandatory_genes_required': 'set_1/T2SS 5 set_1/Flagellum 9', 'replicon_topology': 'circular', 'sequence_db': '/path/to/sequence/bank/fasta_file', 'topology_file': '/the/path/to/the/topology/to/use' } self.assertDictEqual(expected, res) bad_cfg_file = self.find_data( os.path.join('conf_files', 'macsy_test_bad_conf.conf')) with self.assertRaises(ParsingError): cfg._config_file_2_dict(self.defaults, [bad_cfg_file])
def test_save(self): self.parsed_args.max_nb_genes = [['Set_1/T2SS', 5], ['set_1/Flagelum', 12]] self.parsed_args.multi_loci = 'Set_1/T2SS,set_1/Flagelum' self.parsed_args.models = [['Set_1', 'T9SS', 'T3SS', 'T4SS_typeI']] cfg = Config(self.defaults, self.parsed_args) expected = {k: v for k, v in cfg._options.items() if v is not None} expected['max_nb_genes'] = 'Set_1/T2SS 5 set_1/Flagelum 12' expected['models'] = [('models_1', 'Set_1 T9SS T3SS T4SS_typeI')] with tempfile.TemporaryDirectory() as tmpdirname: cfg_path = os.path.join(tmpdirname, 'macsyfinder.conf') cfg.save(path_or_buf=cfg_path) saved_opt = cfg._config_file_2_dict(self.defaults, [cfg_path]) saved_opt['multi_loci'] = { v for v in [v.strip() for v in saved_opt['multi_loci'].split(',')] if v } self.maxDiff = None self.assertDictEqual(saved_opt, expected)