def test_check_prereqs(self): "Test active_site_finder.check_prereqs method" # THIS TEST HAS TO BE UPDATED WHEN NEW PROFILES ARE ADDED TO THE MODULE! self.tt = TraceTracker() mock('utils.locate_executable', returns="/my/path/to/executable", tracker=self.tt) mock('utils.locate_file', returns="/my/path/to/file", tracker=self.tt) result = self.my_ASF.check_prereqs() self.assertListEqual(result, [], "return empty list if executables/files are found") expected = """ Called utils.locate_executable('blastp') Called utils.locate_executable('hmmpfam2') Called utils.locate_executable('hmmscan') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KR.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KS_N.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KS_C.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-AT.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-ACP.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-DH.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-KR.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/Thioesterase.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-ER.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/PKSI-AT.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/aa-activating.aroundLys.hmm2') Called utils.locate_file( '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3')""" assert_same_trace(self.tt, expected) restore() self.tt = TraceTracker() mock('utils.locate_executable', returns=None, tracker=self.tt) mock('utils.locate_file', returns="/my/path/to/file", tracker=self.tt) result = self.my_ASF.check_prereqs() expected = ["Failed to locate file: 'blastp'", "Failed to locate file: 'hmmpfam2'", "Failed to locate file: 'hmmscan'"] self.assertListEqual(result, expected, "test result if file not found") restore()
def setUp(self): self._old_max_evalue = cluster_hmmer.MAX_EVALUE self._old_min_score = cluster_hmmer.MIN_SCORE cluster_hmmer.MAX_EVALUE = 0.02 cluster_hmmer.MIN_SCORE = 1. self.config = build_config([], isolated=True, modules=antismash.get_all_modules()) self.latest_pfam = pfamdb.find_latest_database_version( self.config.database_dir) self.tracer = TraceTracker() self.file_list = [ 'Pfam-A.hmm', 'Pfam-A.hmm.h3f', 'Pfam-A.hmm.h3i', 'Pfam-A.hmm.h3m', 'Pfam-A.hmm.h3p' ] mock('antismash.common.path.locate_file', returns_iter=self.file_list, tracker=self.tracer) mock('antismash.common.subprocessing.run_hmmscan', returns=[]) self.expected_trace = """Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3f') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3i') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3m') Called antismash.common.path.locate_file( '{0}/pfam/{1}/Pfam-A.hmm.h3p')""".format(self.config.database_dir, self.latest_pfam)
def setUp(self): self.config = Namespace() self.tt = TraceTracker() self.fake_features = [ _make_fake_feature(10, 20, 0.1, 'FAKE007'), _make_fake_feature(30, 40, 0.3, 'PF00106'), _make_fake_feature(50, 60, 0.4, 'PF00107'), _make_fake_feature(60, 70, 0.7, 'PF00109'), _make_fake_feature(70, 80, 0.98, 'PF08484'), _make_fake_feature(90, 100, 0.8, 'PF02401'), _make_fake_feature(100, 110, 0.32, 'PF04369'), _make_fake_feature(110, 120, 1.0, 'PF00128'), _make_fake_feature(130, 140, 0.2, 'FAKE234'), _make_fake_feature(500, 505, pfam_id='FAKE505'), _make_fake_feature(1010, 1020, 0.1, 'FAKE007'), _make_fake_feature(1030, 1040, 0.3, 'PF00106'), _make_fake_feature(1050, 1060, 0.4, 'PF00107'), _make_fake_feature(1060, 1070, 0.7, 'PF00109'), _make_fake_feature(1070, 1080, 0.98, 'PF08484'), _make_fake_feature(1090, 1100, 0.8, 'PF02401'), _make_fake_feature(1100, 1110, 0.32, 'PF04369'), _make_fake_feature(1110, 1120, 1.0, 'PF00128'), ] mock('antismash.utils.get_cds_features', tracker=self.tt, returns=self.fake_features) self.config.cdsnr = 5 self.config.cf_prob_thres = 0.6 self.config.cf_npfams = 5 self.config.borderpredict = False
def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response
def setUp(self): self.tt = TraceTracker() self.options = Namespace(full_hmmer=True, clusterblast=True, subclusterblast=True, knownclusterblast=True, smcogs=True) mock('antismash.generic_modules.fullhmmer.check_prereqs', returns=['fullhmmer'], tracker=self.tt) mock('antismash.generic_modules.genefinding.check_prereqs', returns=['genefinding'], tracker=self.tt) mock('antismash.generic_modules.hmm_detection.check_prereqs', returns=['hmm_detection'], tracker=self.tt) mock('antismash.generic_modules.clusterblast.check_prereqs', returns=['clusterblast'], tracker=self.tt) mock('antismash.generic_modules.subclusterblast.check_prereqs', returns=['subclusterblast'], tracker=self.tt) mock('antismash.generic_modules.knownclusterblast.check_prereqs', returns=['knownclusterblast'], tracker=self.tt) mock('antismash.generic_modules.smcogs.check_prereqs', returns=['smcogs'], tracker=self.tt)
def setUp(self): self.trace_tracker = TraceTracker() def fake_exit(code): raise IntTestExit(code) mock("sys.exit", tt=self.trace_tracker, returns_func=fake_exit)
def setUp(self): self.rec = FakeRecord() self.types = [ "CDS", "gene", "CDS", "PFAM_domain", "cluster", "CDS", "aSDomain", ] idx = 1 for t in self.types: f = FakeFeature(t) f.qualifiers['locus_tag'] = ["orf%04d" % idx] f.qualifiers['note'] = [ 'PFAM-Id: PF%05d' % idx, 'smCOG: SMCOG{0:04d}:FAKE{0:04d} (Score: {0} ; E-value: 1.1e-1{0};' .format(idx) ] f.qualifiers['db_xref'] = ['PFAM: PF%05d' % idx] f.qualifiers['translation'] = ['FAKESEQ'] self.rec.features.append(f) idx += 1 self.trace_tracker = TraceTracker()
def setUp(self): self.tt = TraceTracker() mock('helperlibs.bio.seqio.write', tracker=self.tt) self.options = Mock('options', tracker=self.tt, outputfoldername='test', input_type='nucl') rec1_features = [ generate_cluster_feature(23, 42, 'lantipeptide', 1), generate_cluster_feature(300, 500, 'nrps', 2) ] rec2_features = [ generate_cluster_feature(50, 70, 'lassopeptide', 3), generate_cluster_feature(500, 700, 't1pks', 4) ] record1 = SeqRecord(UnknownSeq(1000), 'record1', name='record1', features=rec1_features) record2 = SeqRecord(UnknownSeq(1000), 'record2', name='record2', features=rec2_features) self.records = [record1, record2] self.expected_template = """\
def setUp(self): self.tt = TraceTracker() self.cwd = '/old/cur/dir' mock("tempfile.mkdtemp", tracker=self.tt, returns="/fake/tmp/dir") mock("shutil.rmtree", tracker=self.tt) mock("os.getcwd", tracker=self.tt, returns=self.cwd) mock("os.chdir", tracker=self.tt, returns_func=self._fake_chdir)
def test__execute_tool(self): "Test active_site_finder._execute_tool method" self.tt = TraceTracker() self.tt2 = TraceTracker() mock('utils.execute', returns=["shell output", 0, 0], tracker=self.tt) mock('SearchIO.parse', returns=["SearchIO object"], tracker=self.tt2) result = self.my_ASF._execute_tool(self.ETObj.find('./analysis'), fileName="testTempfile") self.assertListEqual(result, ["SearchIO object"]) expected = """ Called utils.execute( ['hmmscan', '--domE', '0.1', '--cpu', '1', '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3', 'testTempfile']) """ assert_same_trace(self.tt, expected) expected = " Called SearchIO.parse(<cStringIO.StringI object at ...>, 'hmmer3-text')" assert_same_trace(self.tt2, expected) restore() self.tt = TraceTracker() self.tt2 = TraceTracker() mock('utils.execute', returns=["shell output", 0, 0], tracker=self.tt) mock('SearchIO.parse', returns=["SearchIO object"], tracker=self.tt2) result = self.my_ASF._execute_tool( self.ETObj.find('./analysis'), stdin_data="fasta sequence from stdin") self.assertListEqual(result, ["SearchIO object"]) expected = """ Called utils.execute( ['hmmscan', '--domE', '0.1', '--cpu', '1', '.../antismash/generic_modules/active_site_finder/hmm/p450.hmm3'], input='fasta sequence from stdin') """ assert_same_trace(self.tt, expected) expected = " Called SearchIO.parse(<cStringIO.StringI object at ...>, 'hmmer3-text')" assert_same_trace(self.tt2, expected) restore() self.tt = TraceTracker() del self.tt2
def setUp(self): self.tracker = TraceTracker() self.locate_exe = Mock('antismash.common.path.locate_executable', tracker=self.tracker, returns="/fake/path/to/binary") mock('antismash.common.path.locate_executable', mock_obj=self.locate_exe, tracker=self.tracker)
def setUp(self): "set up database test framework and test for db connection" self.options = Namespace() self.options.BioSQLconfig = Namespace() self.options.BioSQLconfig.dbdriver = 'psycopg2' self.options.BioSQLconfig.dbuser = '******' self.options.BioSQLconfig.dbpass = '******' self.options.BioSQLconfig.dbhost = 'localhost' self.options.BioSQLconfig.dbport = '5432' self.options.BioSQLconfig.dbdb = 'antiSMASHnosetest' self.options.BioSQLnamespace = 'test' self.trace_tracker = TraceTracker() # test correct method call for db.asDB)() mock('BioSeqDatabase.open_database', tracker=self.trace_tracker, returns=['mock result']) expected = """Called BioSeqDatabase.open_database( db='antiSMASHnosetest', driver='psycopg2', host='localhost', passwd='biosql', port='5432', user='******') """ mydb = db.aSDB(self.options) assert_same_trace(self.trace_tracker, expected) # restore mocked objects that other tests can run with the original code restore() self.trace_tracker = TraceTracker() #test initializing database object db.__init__" try: mydb = db.aSDB(self.options) except Exception: self.skipTest( 'database connection could not be established, skipping tests') self.assertIsInstance(mydb, db.aSDB) self.mydb = mydb
def test__init(self): "Test active_site_finder.__init__ method" self.tt = TraceTracker() class dummyET: def __init__(self): pass def getroot(self): return dummyET() def findall(self, a): return "ET-Subtree" mock('ET.parse', returns=dummyET(), tracker=self.tt) #mock('ET.getroot', returns="XMLTree", tracker=self.tt) #mock('ET.findall', returns="XMLSubtree", tracker=self.tt) mock( 'antismash.generic_modules.active_site_finder.active_site_finder.check_prereqs', returns=[], tracker=self.tt) expected = """ Called ET.parse( '.../antismash/generic_modules/active_site_finder/config/SignatureResources.xml')""" ASF = antismash.generic_modules.active_site_finder.active_site_finder( self.seq_record, self.options) assert_same_trace(self.tt, expected) # restore mocked objects that other tests can run with the original code restore() self.tt = TraceTracker() # now acutally generate ASF object myASF = antismash.generic_modules.active_site_finder.active_site_finder( self.seq_record, self.options) assert_is_instance( myASF, antismash.generic_modules.active_site_finder.active_site_finder) self.my_ASF = myASF
def setUp(self): """Mock out httplib.HTTPConnection and httplib.HTTPSConnection""" self.trace_tracker = TraceTracker() self.conn = Mock('httplib.HTTPConnection', tracker=self.trace_tracker) mock('httplib.HTTPConnection', mock_obj=self.conn) mock('httplib.HTTPSConnection', mock_obj=self.conn) self.conn.mock_returns = self.conn
def setUp(self): self.maxDiff = None self.tt = TraceTracker() self.locate_exe = Mock('antismash.utils.locate_executable', tracker=self.tt, returns="/fake/path/to/binary") mock('antismash.utils.locate_executable', mock_obj=self.locate_exe, tracker=self.tt)
def setUp(self): self.tt = TraceTracker() # Fall over when we try to call the real download functions mock('utils.fix_supercontig_record', tracker=self.tt, raises=NotImplementedError) mock('utils.fix_wgs_master_record', tracker=self.tt, raises=NotImplementedError)
def setUp(self): self.api = MediaMosaAPI('http://video.example.com') self.tt = TraceTracker() mock('self.api.session', tracker=self.tt) self.response = Mock('requests.Response') self.response.status_code = 200 self.api.session.get.mock_returns = self.response self.partial_dict = { u'is_original_file': u'FALSE', u'is_streamable': u'FALSE', u'is_downloadable': u'FALSE', u'app_id': u'2', u'transcode_inherits_acl': u'TRUE', u'tag': '', u'response_metafile_available': u'TRUE', u'mediafile_id_source': u'u2ilZNiHdl7iNUdexL7BcFMY', u'asset_id': u'g1QkoSmSeHdWfGkMKlOlldLn', u'mediafile_id': u'Md2RgaUEVFhfJMeUIbwPOMei', u'transcode_profile_id': u'17', u'filename': u'Sintel_Trailer1.1080p.DivX_Plus_HD.mp4', u'is_protected': u'FALSE', u'ega_stream_url': '', u'file_extension': u'mp4', 'metadata': { u'is_inserted_md': u'FALSE', u'fps': u'24', u'bpp': u'0.31', u'file_duration': u'00:00:52.20', u'colorspace': u'yuv420p', u'container_type': u'mov;mp4;m4a;3gp;3g2;mj2', u'height': u'478', u'channels': u'stereo', u'width': u'852', u'sample_rate': u'44100', u'filesize': u'20543936', u'audio_codec': u'aac', u'video_codec': u'h264', u'is_hinted': u'TRUE', u'bitrate': u'3012', u'mime_type': u'video/mp4' }, u'ega_download_url': '', u'ega_play_url': '', u'tool': u'ffmpeg', u'response_plain_available': u'TRUE', u'owner_id': u'krkeppen', u'response_object_available': u'TRUE', u'created': u'2012-07-05 11:38:14', u'changed': u'2012-07-05 11:38:14', u'uri': '', u'is_still': u'FALSE', u'command': u'audiocodec:libfaac;audiobitrate:128000;audiosamplingrate:44100;audiochannels:2;videocodec:libx264;videopreset_quality:slow;videopreset_profile:baseline;2_pass_h264_encoding:2;videobitrate:800000;qmax:17;size:852x480;maintain_aspect_ratio:yes', u'group_id': '' }
def setUp(self): self.tt = TraceTracker() mock('helperlibs.bio.seqio.write', tracker=self.tt) self.options = Mock('options', tracker=self.tt, outputfoldername='test', input_type='nucl') record1 = Mock('record1', tracker=self.tt, id='record1', features=[]) record2 = Mock('record2', tracker=self.tt, id='record2', features=[]) self.records = [record1, record2]
def setUp(self): self.config = Namespace() self.config.cpus = 2 config.set_config(self.config) self.tt = TraceTracker() proc = Mock('proc', tracker=self.tt, returncode=0) proc.communicate = Mock('proc.communicate', returns=('output', 'error'), tracker=self.tt) mock('subprocess.Popen', tracker=self.tt, returns=proc)
def setUp(self): self.api_key = "consumer key" self.consumer = oauth.Consumer(self.api_key, "consumer secret") self.access_token = oauth.Token("oauth token", "oauth token secret") self.client = pyblr.Pyblr( oauth.Client(self.consumer, self.access_token)) self.params = {"name": "toqoz", "sex": "male"} self.parsed_params = "name=toqoz&sex=male" self.trackar = TraceTracker() mock("pyblr.Pyblr.get", tracker=self.trackar) mock("pyblr.Pyblr.post", tracker=self.trackar)
def setUp(self): self.config = Namespace() self.config.cpus = 2 config.set_config(self.config) self.tt = TraceTracker() proc = Mock('proc', tracker=self.tt, returncode=0) proc.communicate = Mock('proc.communicate', returns=('output', 'error'), tracker=self.tt) mock('subprocess.Popen', tracker=self.tt, returns=proc) self.tmpdir = tempfile.mkdtemp(prefix="as_tests_util")
def test__run_external_tool(self): "Test active_site_finder._run_external_tool method" self.tt = TraceTracker() SeqFeatureList = utils.get_all_features_of_type_with_query(self.seq_record, "PFAM_domain", "domain", "p450") self.assertEqual(6, len(SeqFeatureList)) mock('antismash.generic_modules.active_site_finder.active_site_finder._execute_tool', returns=["external program call successful"], tracker=self.tt) result = self.my_ASF._run_external_tool(self.ETObj.find('./analysis'), SeqFeatureList) expected = ["external program call successful"] self.assertListEqual(result, expected)
def test_generate_confirmation_mail(): """Test generation of a confirmation email""" # abuse the TraceTracker to make use of doctest features tt = TraceTracker() mail = utils.generate_confirmation_mail(message="Test!") tt.out.write(mail) expected = """We have received your feedback to antiSMASH and will reply to you as soon as possible. Your message was: <BLANKLINE> Test! """ assert_same_trace(tt, expected)
def setUp(self): f_config = Namespace(score='1', evalue='0.02') self.config = Namespace(fullhmmer=f_config) self.tt = TraceTracker() mock('antismash.utils.locate_executable', returns='hmmsearch', tracker=self.tt) self.file_list = [ 'Pfam-A.hmm', 'Pfam-A.hmm.h3f', 'Pfam-A.hmm.h3i', 'Pfam-A.hmm.h3m', 'Pfam-A.hmm.h3p' ] mock('antismash.utils.locate_file', returns_iter=self.file_list, tracker=self.tt) mock('antismash.utils.run_hmmscan', returns=[])
def setUp(self): "set up database connection" # restore all mocked methods restore() #Open testfile and parse it with Biopython testfile = path.join(path.dirname(__file__), "AAA26493.embl") testfile_fh = open(testfile, "rU") self.seq_record = SeqIO.read(testfile_fh, 'embl') self.options = Namespace() self.options.BioSQLconfig = Namespace() self.options.BioSQLconfig.dbdriver = 'psycopg2' self.options.BioSQLconfig.dbuser = '******' self.options.BioSQLconfig.dbpass = '******' self.options.BioSQLconfig.dbhost = 'localhost' self.options.BioSQLconfig.dbport = '5432' self.options.BioSQLconfig.dbdb = 'antiSMASHnosetest' self.options.BioSQLnamespace = 'test' self.options.dbnamespace = self.options.BioSQLnamespace self.trace_tracker = TraceTracker() try: mydb = db.aSDB(self.options) except Exception: self.skipTest( 'database connection could not be established, skipping tests') if not mydb: self.skipTest('database connection impossible; skipping tests') try: del mydb.server[self.options.BioSQLnamespace] mydb.commit() except Exception: pass mydb.generate_namespace(self.options.BioSQLnamespace, 'test namespace for nosetests') mydb.connect(self.options.BioSQLnamespace) rec_no = mydb.load_records([self.seq_record]) mydb.commit() self.mydb = mydb
def test_get_record(self): "Test get_record() function" Fake_seq_rec = Namespace() Fake_seq_rec.name = 'fakedName' mock('db.aSDB.get_record_by_name', tracker=self.trace_tracker, returns=Fake_seq_rec) db_seq_rec = db.get_record('AAA26493', self.options) expected = "Called db.aSDB.get_record_by_name('AAA26493')" assert_same_trace(self.trace_tracker, expected) restore() self.trace_tracker = TraceTracker() db_seq_rec = db.get_record('AAA26493', self.options) myrecord_class = db_seq_rec.__class__.__name__ self.assertEqual(myrecord_class, "DBSeqRecord") self.assertEqual(str(db_seq_rec.seq), str(self.seq_record.seq)) self.assertEqual(db_seq_rec.id, self.seq_record.id) self.assertEqual(db_seq_rec.name, self.seq_record.name)
def setUp(self): self.tt = TraceTracker() mock('utils.get_aa_sequence', tracker=self.tt, returns="FAKESEQ")
def setUp(self): self.tt = TraceTracker() self.hmmpfam_return_vals = [] mock('utils.run_hmmpfam2', tracker=self.tt, returns=self.hmmpfam_return_vals)
def setUp(self): self.trace_tracker = TraceTracker() self.hmmpfam_return_vals = [] mock('subprocessing.run_hmmpfam2', tracker=self.trace_tracker, returns=self.hmmpfam_return_vals)
def setUp(self): self.trace_tracker = TraceTracker() mock('logging.debug', tracker=self.trace_tracker, returns=None)