class TestCoreGene(MacsyTest): def setUp(self): args = argparse.Namespace() args.sequence_db = self.find_data("base", "test_1.fasta") args.db_type = 'gembase' args.models_dir = self.find_data('models') args.res_search_dir = tempfile.gettempdir() args.log_level = 30 self.cfg = Config(MacsyDefaults(), args) self.model_name = 'foo' self.model_location = ModelLocation(path=os.path.join(args.models_dir, self.model_name)) self.profile_factory = ProfileFactory(self.cfg) def tearDown(self): try: shutil.rmtree(self.cfg.working_dir()) except: pass def test_core_gene(self): model_fqn = "foo/bar" model = Model(model_fqn, 10) gene_name = 'toto' cg = CoreGene(self.model_location, gene_name, self.profile_factory) self.assertEqual(cg.name, gene_name) self.assertEqual(cg.model_family_name, model.family_name) self.assertEqual(cg.profile, self.profile_factory.get_profile(cg, self.model_location)) cg2 = CoreGene(self.model_location, gene_name, self.profile_factory) self.assertTrue(isinstance(hash(cg), int)) self.assertEqual(hash(cg), hash(cg2)) gene_name = 'totote' cg3 = CoreGene(self.model_location, gene_name, self.profile_factory) self.assertNotEqual(hash(cg), hash(cg3))
class TestProfileFactory(MacsyTest): def setUp(self): args = argparse.Namespace() args.sequence_db = self.find_data("base", "test_1.fasta") args.db_type = 'gembase' args.models_dir = self.find_data('models') args.res_search_dir = tempfile.gettempdir() args.log_level = 30 self.cfg = Config(MacsyDefaults(), args) self.model_name = 'foo' self.models_location = ModelLocation( path=os.path.join(args.models_dir, self.model_name)) self.profile_factory = ProfileFactory(self.cfg) def tearDown(self): try: shutil.rmtree(self.cfg.working_dir) except: pass def test_get_profile(self): gene_name = 'sctJ_FLG' gene = CoreGene(self.models_location, gene_name, self.profile_factory) profile = self.profile_factory.get_profile(gene, self.models_location) self.assertTrue(isinstance(profile, Profile)) self.assertEqual(profile.gene.name, gene_name) def test_get_uniq_object(self): gene_name = 'sctJ_FLG' gene = CoreGene(self.models_location, gene_name, self.profile_factory) profile1 = self.profile_factory.get_profile(gene, self.models_location) profile2 = self.profile_factory.get_profile(gene, self.models_location) self.assertEqual(profile1, profile2) def test_unknow_profile(self): gene_name = 'sctJ_FLG' gene = CoreGene(self.models_location, gene_name, self.profile_factory) gene._name = "bar" with self.assertRaises(MacsypyError) as ctx: self.profile_factory.get_profile(gene, self.models_location) self.assertEqual(str(ctx.exception), f"'{self.model_name}/{gene.name}': No such profile")