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)
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 __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_can_run(self): temp_dir = tempfile.mkdtemp() try: params = D3RParameters() # no dock task found so it cannot run docktask = D3RTask(temp_dir, params) docktask.set_name('foo') docktask.set_stage(EvaluationTaskFactory.DOCKSTAGE) evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) self.assertEqual(evaluation.can_run(), False) self.assertEqual(evaluation.get_error(), 'foo task has notfound status') # docktask running 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.START_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) self.assertEqual(evaluation.can_run(), False) self.assertEqual(evaluation.get_error(), 'foo task has start status') # docktask failed error_file = os.path.join(docktask.get_dir(), D3RTask.ERROR_FILE) open(error_file, 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) self.assertEqual(evaluation.can_run(), False) self.assertEqual(evaluation.get_error(), 'foo task has error status') # docktask success os.remove(error_file) open(os.path.join(docktask.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) self.assertEqual(evaluation.can_run(), True) self.assertEqual(evaluation.get_error(), None) # evaluation task exists already evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) evaluation.create_dir() self.assertEqual(evaluation.can_run(), False) self.assertEqual( evaluation.get_error(), evaluation.get_dir_name() + ' already exists and status is unknown') # evaluation task already complete evaluation = EvaluationTask(temp_dir, 'foo.evaluation', docktask, params) open(os.path.join(evaluation.get_dir(), D3RTask.COMPLETE_FILE), 'a').close() self.assertEqual(evaluation.can_run(), False) self.assertEqual(evaluation.get_error(), None) finally: shutil.rmtree(temp_dir)