def test_get_rmsd_pickle(self): params = D3RParameters() task = EvaluationTask('/ha', 'foo', None, params) self.assertEqual( task.get_rmsd_pickle(), os.path.join('/ha', task.get_dir_name(), EvaluationTask.RMSD_PICKLE))
def test_get_evaluation_summary(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() task = EvaluationTask(temp_dir, 'foo', None, params) # test where no RMSD.txt file is found val = task.get_evaluation_summary() self.assertEqual( val, '\nEvaluation of docking\n' '=====================\nNo ' + task.get_rmsd_txt() + ' file found.\n') # test with valid RMSD.txt file task.create_dir() f = open(task.get_rmsd_txt(), 'w') f.write('LMCSS\n1fcz 0.465\n') f.flush() f.close() val = task.get_evaluation_summary() self.assertEqual( val, '\nEvaluation of docking\n' '=====================\n' 'LMCSS\n1fcz 0.465\n\n') # test where reading RMSD.txt throws exception os.chmod(task.get_rmsd_txt(), 0) val = task.get_evaluation_summary() self.assertTrue( val.startswith('\nEvaluation of docking\n' '=====================\n' 'Unable to generate evaluation' ' summary (')) finally: shutil.rmtree(temp_dir)
def test_send_external_submission_email_success(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.program = 'foo' params.version = '1' dtask = D3RTask('/foo', params) dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params) task.create_dir() f = open(task.get_rmsd_txt(), 'w') f.write('hi\n') f.flush() f.close() plist = [ Participant('1name', '1d3rusername', '12345', '*****@*****.**') ] # try single email address smtpemailer = SmtpEmailer() mockserver = D3RParameters() mockserver.sendmail = Mock() mockserver.quit = Mock() smtpemailer.set_alternate_smtp_server(mockserver) emailer = EvaluationEmailer(ParticipantDatabase(plist), None) emailer.set_alternate_smtp_emailer(smtpemailer) emailer.send_evaluation_email(task) mockserver.quit.assert_any_call() self.assertEqual(emailer.get_message_log(), '\nSent evaluation email to: [email protected]\n') self.assertEqual(mockserver.sendmail.call_count, 1) finally: shutil.rmtree(temp_dir)
def test_run_fails_one_evaluation_and_no_emailer(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.postevaluation = 'false' etask = EvaluationTask( temp_dir, 'foo_dock.' + EvaluationTaskFactory.SCORING_SUFFIX, None, params) etask.create_dir() task = PostEvaluationTask(temp_dir, params) task.run() self.assertEqual( task.get_error(), 'Non zero exit code: 1 received. ' 'Standard out: Standard error: ') self.assertEqual(task.get_status(), D3RTask.ERROR_STATUS) self.assertTrue( os.path.isfile(os.path.join(task.get_dir(), D3RTask.ERROR_FILE))) self.assertTrue('Caught exception trying to ' 'send evaluation email' in task.get_email_log()) stdout_file = os.path.join(task.get_dir(), 'false' + D3RTask.STDOUT_SUFFIX) self.assertTrue(os.path.isfile(stdout_file)) stderr_file = os.path.join(task.get_dir(), 'false' + D3RTask.STDERR_SUFFIX) self.assertTrue(os.path.isfile(stderr_file)) finally: shutil.rmtree(temp_dir)
def test_is_external_submission(self): params = D3RParameters() dtask = D3RTask('/ha', params) task = EvaluationTask('/ha', 'foo', dtask, params) dtask.set_name('blah') self.assertEqual(task.is_external_submission(), False) dtask.set_name('blah' + EvaluationTask.EXT_SUBMISSION_SUFFIX) self.assertEqual(task.is_external_submission(), True)
def test_run_succeeds_no_emailer(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.evaluation = 'true' params.pdbdb = '/data/pdb' docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) docktask.create_dir() open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.run() self.assertEqual(evaluation.get_error(), None) # test files get created errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), False) compfile = os.path.join(evaluation.get_dir(), D3RTask.COMPLETE_FILE) self.assertEqual(os.path.isfile(compfile), True) stderr = os.path.join(evaluation.get_dir(), 'true.stderr') self.assertEqual(os.path.isfile(stderr), True) stdout = os.path.join(evaluation.get_dir(), 'true.stdout') self.assertEqual(os.path.isfile(stdout), True) finally: shutil.rmtree(temp_dir)
def test_evaluationtask_constructor(self): params = D3RParameters() # no dock task found so it cannot run docktask = D3RTask('/blah', params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) evaluation = EvaluationTask('/blah', 'foo.evaluation', docktask, params) self.assertEquals(evaluation.get_name(), 'foo.evaluation') self.assertEquals(evaluation.get_stage(), 7)
def __init__(self, path, args): super(PostEvaluationTask, self).__init__(path, args) self.set_name(PostEvaluationTask.TASK_NAME) et = EvaluationTask('/foo', '', None, None) self._eval_task_prefix_str = et.get_dir_name() self._eval_task_suffix_str = ( '' + EvaluationTask.EXT_SUBMISSION_SUFFIX + '.' + EvaluationTaskFactory.SCORING_SUFFIX + '$|.' + EvaluationTaskFactory.SCORING_SUFFIX + '$') self.set_stage(et.get_stage() + 1) self._emailer = None self.set_status(D3RTask.UNKNOWN_STATUS)
def test_run_fails_cause_evaluation_fails(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.evaluation = 'false' params.pdbdb = '/data/pdb' docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) docktask.create_dir() open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.run() self.assertEqual( evaluation.get_error(), 'Non zero exit code: 1 received. Standard out: ' + ' Standard error: ') # test file gets created errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) stderr = os.path.join(evaluation.get_dir(), 'false.stderr') self.assertEqual(os.path.isfile(stderr), True) stdout = os.path.join(evaluation.get_dir(), 'false.stdout') self.assertEqual(os.path.isfile(stdout), True) finally: shutil.rmtree(temp_dir)
def test_run_fails_cause_can_run_is_false(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() # return immediately cause can_run is false docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.run() self.assertEqual(evaluation.get_error(), 'foo task has notfound status') finally: shutil.rmtree(temp_dir)
def test_send_external_submission_email_sendmail_exception(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.program = 'foo' params.version = '1' dtask = D3RTask('/foo', params) dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params) plist = [ Participant('1name', '1d3rusername', '12345', '*****@*****.**') ] # try single email address smtpemailer = SmtpEmailer() mockserver = D3RParameters() mockserver.sendmail = Mock(side_effect=IOError('ha')) mockserver.quit = Mock() smtpemailer.set_alternate_smtp_server(mockserver) emailer = EvaluationEmailer(ParticipantDatabase(plist), None) emailer.set_alternate_smtp_emailer(smtpemailer) emailer.send_evaluation_email(task) mockserver.quit.assert_any_call() self.assertEqual( emailer.get_message_log(), '\nCaught exception trying to email ' 'participant : Caught exception ha\n') finally: shutil.rmtree(temp_dir)
def test_get_external_submitter_email_valid(self): params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask('/foo', dtask.get_name(), dtask, params) plist = [Participant('1name', '1d3rusername', '12345', '*****@*****.**')] # try single email address emailer = EvaluationEmailer(ParticipantDatabase(plist), None) emails = emailer._get_external_submitter_email(task) self.assertEqual(emails[0], '*****@*****.**') self.assertEqual(len(emails), 1) self.assertEqual(emailer.get_message_log(), None) # try multiple email address plist = [ Participant('1name', '1d3rusername', '12345', '[email protected],[email protected]') ] # try single email address emailer = EvaluationEmailer(ParticipantDatabase(plist), None) emails = emailer._get_external_submitter_email(task) self.assertEqual(emails[0], '*****@*****.**') self.assertEqual(emails[1], '*****@*****.**') self.assertEqual(len(emails), 2) self.assertEqual(emailer.get_message_log(), None)
def test_eval_emailer_get_external_submitter_email_none_from_guid(self): emailer = EvaluationEmailer(None, None) params = D3RParameters() task = EvaluationTask('/foo', None, None, params) self.assertEqual(emailer._get_external_submitter_email(task), None) self.assertEqual(emailer.get_message_log(), '\nUnable to extract guid\n')
def test_send_evaluation_email_not_external_task(self): emailer = EvaluationEmailer(None, None) task = EvaluationTask('/foo', 'blah' + EvaluationTask.EXT_SUBMISSION_SUFFIX, None, D3RParameters()) emailer.send_evaluation_email(task) self.assertEqual(emailer.get_message_log(), '\nNot an external submission\n')
def get_all_evaluation_tasks(self): """Look for all evaluation tasks """ task_list = [] prefix_len = len(self._eval_task_prefix_str) base_dir = self.get_path() for entry in os.listdir(base_dir): if not entry.endswith('.' + EvaluationTaskFactory.SCORING_SUFFIX): continue full_path = os.path.join(base_dir, entry) if not os.path.isdir(full_path): logger.info('Suffix matched, but is not directory: ' + full_path) self.append_to_email_log('Just a note, found a task ' + 'with valid name, but it is not ' 'a directory ' + full_path) continue task = EvaluationTask(base_dir, entry[prefix_len:], None, self.get_args()) task.update_status_from_filesystem() if task.get_status() != D3RTask.COMPLETE_STATUS: logger.info('fyi ' + task.get_name() + ' task ' + ' has a status of ' + task.get_status()) task_list.append(task) return task_list
def test_generate_external_submission_email_body(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('foo') task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params) task.create_dir() emailer = EvaluationEmailer(None, None) task.set_evaluation_emailer(emailer) rmsd = task.get_rmsd_txt() f = open(rmsd, 'w') f.write(' LMCSS XXX\n1fcz 0.2 0.4\n') f.flush() f.close() subject, body = emailer\ ._generate_external_submission_email_body(task) self.assertEqual(subject, '[d3rcelpp] Week 0 evaluation results for foo') self.assertEqual( body, 'Dear CELPP Participant,\n\nHere are your ' 'docking evaluation results ' '(RMSD, Angstroms) ' 'for CELPP week ' '0\n\n\nEvaluation of docking' '\n=====================\n LMCSS XXX\n' '1fcz 0.2 0.4\n\n\n\nSincerely,\n\n' 'CELPP Automation') finally: shutil.rmtree(temp_dir)
def test_run_fails_cause_evaluation_is_not_found(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.evaluation = '/bin/doesnotexist' params.pdbdb = '/data/pdb' docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) docktask.create_dir() open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.run() self.assertEqual( evaluation.get_error(), 'Caught Exception trying to run ' + '/bin/doesnotexist --pdbdb /data/pdb ' + '--dockdir ' + docktask.get_dir() + ' --outdir ' + evaluation.get_dir() + ' : [Errno 2] No such file or directory') # test files get created errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) finally: shutil.rmtree(temp_dir)
def test_send_evaluation_email_no_database(self): params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('444' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask('/foo', dtask.get_name(), dtask, params) emailer = EvaluationEmailer(None, None) emailer.send_evaluation_email(task) self.assertEqual( emailer.get_message_log(), '\nParticipant database is None cannot send docking ' 'evaluation email!!!\n')
def test_get_external_submitter_email_no_participant_email(self): params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('444' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask('/foo', dtask.get_name(), dtask, params) plist = [Participant('1name', '1d3rusername', '444', None)] emailer = EvaluationEmailer(ParticipantDatabase(plist), None) self.assertEqual(emailer._get_external_submitter_email(task), None) self.assertEqual(emailer.get_message_log(), '\nEmail not set for participant\n')
def test_run_succeeds_one_evaluation_and_no_emailer(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.postevaluation = 'echo' etask = EvaluationTask( temp_dir, 'foo_dock.' + EvaluationTaskFactory.SCORING_SUFFIX, None, params) etask.create_dir() task = PostEvaluationTask(temp_dir, params) ctask = ChallengeDataTask(temp_dir, params) task.run() self.assertEqual(task.get_error(), None) self.assertEqual(task.get_status(), D3RTask.COMPLETE_STATUS) cfile = os.path.join(task.get_dir(), D3RTask.COMPLETE_FILE) self.assertTrue(os.path.isfile(cfile)) stdout_file = os.path.join(task.get_dir(), 'echo' + D3RTask.STDOUT_SUFFIX) self.assertTrue(os.path.isfile(stdout_file)) f = open(stdout_file, 'r') data = f.read() f.close() ctaskdir = os.path.join(ctask.get_dir(), ctask.get_celpp_challenge_data_dir_name()) self.assertTrue(' --evaluationdir ' + etask.get_dir() in data) self.assertTrue(' --challengedir ' + ctaskdir in data) self.assertTrue('--stageprefix stage.7. --evaluationsuffix ' + '.extsubmission.evaluation$|.evaluation$' in data) stderr_file = os.path.join(task.get_dir(), 'echo' + D3RTask.STDERR_SUFFIX) self.assertTrue(os.path.isfile(stderr_file)) finally: shutil.rmtree(temp_dir)
def test_get_evaluation_tasks_on_with_valid_completed_algo_dir(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() glidetask = GlideTask(temp_dir, params) glidetask.create_dir() open(os.path.join(glidetask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() etask = EvaluationTask( temp_dir, glidetask.get_name() + '.' + EvaluationTaskFactory.SCORING_SUFFIX, glidetask, params) etask.create_dir() open(os.path.join(etask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() stf = EvaluationTaskFactory(temp_dir, params) task_list = stf.get_evaluation_tasks() self.assertEquals(len(task_list), 0) finally: shutil.rmtree(temp_dir)
def test_send_external_submission_email_no_submitter_email(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() params.program = 'foo' params.version = '1' dtask = D3RTask('/foo', params) dtask.set_name('12345' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params) plist = [ Participant('1name', '1d3rusername', '1234', '*****@*****.**') ] # try single email address emailer = EvaluationEmailer(ParticipantDatabase(plist), None) smtpemailer = SmtpEmailer() emailer.set_alternate_smtp_emailer(smtpemailer) emailer.send_evaluation_email(task) self.assertEqual(emailer.get_message_log(), '\nNo participant found with guid: 12345\n') finally: shutil.rmtree(temp_dir)
def test_run_fails_cause_evaluation_not_set(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) docktask.create_dir() open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.run() self.assertEqual(evaluation.get_error(), 'evaluation not set') # test files get created self.assertEqual(os.path.isdir(evaluation.get_dir()), True) errfile = os.path.join(evaluation.get_dir(), D3RTask.ERROR_FILE) self.assertEqual(os.path.isfile(errfile), True) finally: shutil.rmtree(temp_dir)
def test_permute_chains_and_take_min_rmsd(self): if not (self.has_oechem) or not (self.has_schrodinger): sys.stdout.write("Missing essential component. Skipping test.") return test_scale = 'github' method_list = ['autodockvina'] try: temp_dir = tempfile.mkdtemp() for method in method_list: params = D3RParameters() params.evaluation = 'evaluate.py' params.pdbdb = os.path.abspath('tests/celpp/eval_test_data/' '%s_test_data/mini_pdb/' % (test_scale)) docktask = D3RTask(temp_dir, params) docktask.set_name(method) docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) docktask.create_dir() open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() source_dir = os.path.abspath('tests/celpp/eval_test_data/' '%s_test_data/stage.6.%s/' % (test_scale, method)) os.system('cp -r %s/* %s' % (source_dir, docktask.get_dir())) task = EvaluationTask(temp_dir, '%s.evaluation' % (method), docktask, params) task.run() val = task.get_evaluation_summary() self.assertEqual( val, '\nEvaluation of docking\n=============' '========\nTarget_PDBID LMCSS ' ' SMCSS hiResApo hiResHolo hiTani' 'moto \nNumber_of_cases 0 0' ' 1 0 0 ' '\nAverage ' ' 6.452 \nMi' 'nimum 6' '.452 \nMaximum ' ' 6.452 ' ' \n5t6d ' ' 6.452 ' ' \n\n') self.assertEqual(task.get_error(), None) finally: shutil.rmtree(temp_dir)
def test_get_external_submitter_email_participant_not_found(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() dimport = DataImportTask(temp_dir, params) dimport.create_dir() csvfile = dimport.get_participant_list_csv() f = open(csvfile, 'w') f.write('name,d3rusername,guid,email\n') f.write('joe,jj,123,[email protected]\n') f.flush() f.close() fac = ParticipantDatabaseFromCSVFactory(csvfile) params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('444' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask(temp_dir, dtask.get_name(), dtask, params) emailer = EvaluationEmailer(fac.get_participant_database(), None) self.assertEqual(emailer._get_external_submitter_email(task), None) self.assertEqual(emailer.get_message_log(), '\nNo participant found with guid: 444\n') finally: shutil.rmtree(temp_dir)
def test_run_succeeds_one_evaluation_with_emailer(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() foo_script = os.path.join(temp_dir, 'foo.py') f = open(foo_script, 'w') f.write('#! /usr/bin/env python\n') f.write('import sys\nimport os\n') f.write('outdir = sys.argv[1]\n') f.write('sys.stdout.write(" ".join(sys.argv))\n') f.write('f = open(os.path.join(outdir, "summary.txt"),"w")\n') f.write('f.write("summary")\n') f.write('f.flush()\nf.close()\n') f.write('f = open(os.path.join(outdir, "yo.csv"), "a")\n') f.write('f.write("hi")\nf.flush()\nf.close()\n') f.write('sys.exit(0)\n') f.flush() f.close() os.chmod(foo_script, stat.S_IRWXU) params.postevaluation = foo_script etask = EvaluationTask( temp_dir, 'foo_dock.' + EvaluationTaskFactory.SCORING_SUFFIX, None, params) etask.create_dir() task = PostEvaluationTask(temp_dir, params) # setup emailer smtpemailer = SmtpEmailer() mockserver = D3RParameters() mockserver.sendmail = Mock() mockserver.quit = Mock() smtpemailer.set_alternate_smtp_server(mockserver) pee = PostEvaluationEmailer(['*****@*****.**'], smtpemailer) task.set_evaluation_emailer(pee) ctask = ChallengeDataTask(temp_dir, params) task.run() self.assertEqual(task.get_error(), None) self.assertEqual(task.get_status(), D3RTask.COMPLETE_STATUS) cfile = os.path.join(task.get_dir(), D3RTask.COMPLETE_FILE) self.assertTrue(os.path.isfile(cfile)) stdout_file = os.path.join(task.get_dir(), 'foo.py' + D3RTask.STDOUT_SUFFIX) self.assertTrue(os.path.isfile(stdout_file)) f = open(stdout_file, 'r') data = f.read() f.close() ctaskdir = os.path.join(ctask.get_dir(), ctask.get_celpp_challenge_data_dir_name()) self.assertTrue(' --evaluationdir ' + etask.get_dir() in data) self.assertTrue(' --challengedir ' + ctaskdir in data) self.assertTrue('--stageprefix stage.7. --evaluationsuffix ' + '.extsubmission.evaluation$|.evaluation$' in data) stderr_file = os.path.join(task.get_dir(), 'foo.py' + D3RTask.STDERR_SUFFIX) f = open(stdout_file, 'r') data = f.read() f.close() self.assertTrue(' --evaluationdir ' + etask.get_dir() in data) self.assertTrue(os.path.isfile(stderr_file)) self.assertEqual(task.get_error(), None) self.assertTrue('Sent post evaluation email to: ' '*****@*****.**' in task.get_email_log()) finally: shutil.rmtree(temp_dir)
def test_get_guid_for_task_dock_is_none(self): params = D3RParameters() task = EvaluationTask('/foo', 'blah' + EvaluationTask.EXT_SUBMISSION_SUFFIX, None, params) self.assertEqual(task.get_guid_for_task(), None)
def test_get_evaluationdir_args(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() # no evaluation tasks task = PostEvaluationTask(temp_dir, params) res = task._get_evaluationdir_args() self.assertEqual(res, '') # one task etask = EvaluationTask(temp_dir, 'foo.evaluation', None, params) etask.create_dir() res = task._get_evaluationdir_args() self.assertEqual( res, ' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' + etask.get_dir()) # three tasks etask2 = EvaluationTask(temp_dir, 'bla_dock.extsubmission.evaluation', None, params) etask2.create_dir() open(os.path.join(etask2.get_dir(), D3RTask.ERROR_FILE), 'a').close() etask3 = EvaluationTask(temp_dir, '12_x.extsubmission.evaluation', None, params) etask3.create_dir() cfile = os.path.join(etask3.get_dir(), D3RTask.COMPLETE_FILE) open(cfile, 'a').close() res = task._get_evaluationdir_args() self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' + etask.get_dir() in res) self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' + etask2.get_dir() in res) self.assertTrue(' ' + PostEvaluationTask.EVALUATIONDIR_ARG + ' ' + etask3.get_dir() in res) finally: shutil.rmtree(temp_dir)
def test_get_guid_for_task(self): params = D3RParameters() dtask = D3RTask('/foo', params) dtask.set_name('123' + EvaluationTask.EXT_SUBMISSION_SUFFIX) task = EvaluationTask('/foo', dtask.get_name(), dtask, params) self.assertEqual(task.get_guid_for_task(), '123')
def test_get_all_evaluation_tasks(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() # no evaluation tasks task = PostEvaluationTask(temp_dir, params) res = task.get_all_evaluation_tasks() self.assertEqual(len(res), 0) # directory in path that does NOT match suffix task.create_dir() os.makedirs(os.path.join(temp_dir, 'stage.x.1'), mode=0o755) res = task.get_all_evaluation_tasks() self.assertEqual(len(res), 0) # one task, but is file (weird case) weirdtaskfile = os.path.join( temp_dir, 'stage.7.hi.' + EvaluationTaskFactory.SCORING_SUFFIX) open(weirdtaskfile, 'a').close() res = task.get_all_evaluation_tasks() self.assertEqual(len(res), 0) self.assertEqual( task.get_email_log(), 'Just a note, found a task with valid name, but ' 'it is not a directory ' + weirdtaskfile) # one task etask = EvaluationTask(temp_dir, 'foo.evaluation', None, params) etask.create_dir() res = task.get_all_evaluation_tasks() self.assertEqual(len(res), 1) self.assertTrue(res[0].get_dir_name(), etask.get_dir_name()) # three tasks two with non complete status etask2 = EvaluationTask(temp_dir, 'bla_dock.extsubmission.evaluation', None, params) etask2.create_dir() open(os.path.join(etask2.get_dir(), D3RTask.ERROR_FILE), 'a').close() etask3 = EvaluationTask(temp_dir, '12_x.extsubmission.evaluation', None, params) etask3.create_dir() open(os.path.join(etask3.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() res = task.get_all_evaluation_tasks() self.assertEqual(len(res), 3) d_name_list = [] for entry in res: d_name_list.append(entry.get_dir_name()) self.assertTrue(etask.get_dir_name() in d_name_list) self.assertTrue(etask2.get_dir_name() in d_name_list) self.assertTrue(etask3.get_dir_name() in d_name_list) finally: shutil.rmtree(temp_dir)