Ejemplo n.º 1
0
 def test_previous_run(self):
     kwargs = {'cfg_file' : "nimportnaoik",
               'sequence_db' : os.path.join(self._data_dir, "base", "test_base.fa"),
               'db_type' : 'gembase',
               'def_dir' : os.path.join(self._data_dir, 'DEF'),
               'profile_dir' : os.path.join(self._data_dir, 'profiles'),
               'previous_run' : 'foo',
               'res_search_dir' : self.tmp_dir
     }
     self.assertRaises(ValueError, Config, **kwargs)
     try:
         cfg_base = Config(cfg_file = "nimportnaoik",
                           sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                           db_type = 'gembase',
                           def_dir = os.path.join(self._data_dir, 'DEF'),
                           profile_dir = os.path.join(self._data_dir, 'profiles'),
                           res_search_dir = self.tmp_dir
                           )
         self.assertIsNone(cfg_base.previous_run)
         cfg_base.save( cfg_base.working_dir )
         #wait
         time.sleep(1)
         new_cfg = Config(previous_run = cfg_base.working_dir)
         self.assertEqual(new_cfg.previous_run, cfg_base.working_dir)
          
     finally:
          
         # close loggers filehandles, so they don't block file deletion
         # in shutil.rmtree calls in Windows
         logging.shutdown()
         try:
             shutil.rmtree(new_cfg.working_dir)
         except:
             pass
Ejemplo n.º 2
0
 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'] = 'Set_1 T9SS T3SS T4SS_typeI'
     # save in file 'macsyfinder.conf'
     with tempfile.TemporaryDirectory() as tmpdirname:
         cfg_path = os.path.join(tmpdirname, 'macsyfinder.conf')
         cfg.save(path_or_buf=cfg_path)
         cfg.save(path_or_buf='/tmp/macsyfinder.conf')
         new_args = Namespace()
         new_args.cfg_file = cfg_path
         restored_cfg = Config(self.defaults, new_args)
         self.maxDiff = None
         # the option cfg-file differ from the 2 configs
         # None in cfg
         # cfg_path in restored_cfg
         self.assertEqual(restored_cfg._options['cfg_file'], cfg_path)
         del (cfg._options['cfg_file'])
         del (restored_cfg._options['cfg_file'])
         self.assertDictEqual(cfg._options, restored_cfg._options)
 def test_previous_run(self):
     kwargs = {'cfg_file' : "nimportnaoik",
               'sequence_db' : os.path.join(self._data_dir, "base", "test_base.fa"),
               'db_type' : 'gembase',
               'def_dir' : os.path.join(self._data_dir, 'DEF'),
               'profile_dir' : os.path.join(self._data_dir, 'profiles'),
               'previous_run' : 'foo',
               'res_search_dir' : '/tmp',
     }
     self.assertRaises(ValueError, Config, **kwargs)
     try:
         cfg_base = Config(cfg_file = "nimportnaoik",
                           sequence_db = os.path.join(self._data_dir, "base", "test_base.fa"),
                           db_type = 'gembase',
                           def_dir = os.path.join(self._data_dir, 'DEF'),
                           profile_dir = os.path.join(self._data_dir, 'profiles'),
                           res_search_dir = '/tmp',
                           )
         self.assertIsNone(cfg_base.previous_run)
         cfg_base.save( cfg_base.working_dir )
         #wait
         time.sleep(1)
         new_cfg = Config(previous_run = cfg_base.working_dir)
         self.assertEqual(new_cfg.previous_run, cfg_base.working_dir)
     finally:
         try:
             shutil.rmtree(cfg_base.working_dir)
         except:
             pass
         try:
             shutil.rmtree(new_cfg.working_dir)
         except:
             pass
Ejemplo n.º 4
0
    def test_previous_run(self):
        out_dir = os.path.join(self.tmp_dir, 'macsy_test_config')
        kwargs = {
            'cfg_file': "nimportnaoik",
            'sequence_db': os.path.join(self._data_dir, "base",
                                        "test_base.fa"),
            'db_type': 'gembase',
            'def_dir': os.path.join(self._data_dir, 'DEF'),
            'profile_dir': os.path.join(self._data_dir, 'profiles'),
            'previous_run': 'foo',
            'res_search_dir': out_dir
        }
        self.assertRaises(ValueError, Config, **kwargs)
        try:
            shutil.rmtree(out_dir)
        except:
            pass
        self.tearDown()
        try:
            cfg_base = Config(cfg_file="nimportnaoik",
                              sequence_db=os.path.join(self._data_dir, "base",
                                                       "test_base.fa"),
                              db_type='gembase',
                              def_dir=os.path.join(self._data_dir, 'DEF'),
                              profile_dir=os.path.join(self._data_dir,
                                                       'profiles'),
                              res_search_dir=self.tmp_dir)
            self.assertIsNone(cfg_base.previous_run)
            cfg_base.save(cfg_base.working_dir)
            #wait
            time.sleep(1)
            new_cfg = Config(previous_run=cfg_base.working_dir)
            self.assertEqual(new_cfg.previous_run, cfg_base.working_dir)

        finally:

            # close loggers filehandles, so they don't block file deletion
            # in shutil.rmtree calls in Windows
            logging.shutdown()
            try:
                shutil.rmtree(new_cfg.working_dir)
            except:
                pass
            try:
                shutil.rmtree(cfg_base.working_dir)
            except:
                pass
Ejemplo n.º 5
0
 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)