def test_read_internal_function(self): with TestAreaContext("python/job_queue/workflow_job"): WorkflowCommon.createInternalFunctionJob() WorkflowCommon.createErtScriptsJob() config = self._alloc_config() workflow_job = self._alloc_from_file("SELECT_CASE", config, "select_case_job") self.assertEqual(workflow_job.name(), "SELECT_CASE") self.assertTrue(workflow_job.isInternal()) self.assertEqual(workflow_job.functionName(), "enkf_main_select_case_JOB") self.assertFalse(workflow_job.isInternalScript()) self.assertIsNone(workflow_job.getInternalScriptPath()) workflow_job = self._alloc_from_file("SUBTRACT", config, "subtract_script_job") self.assertEqual(workflow_job.name(), "SUBTRACT") self.assertTrue(workflow_job.isInternal()) self.assertIsNone(workflow_job.functionName()) self.assertTrue(workflow_job.isInternalScript()) self.assertTrue(workflow_job.getInternalScriptPath().endswith( "subtract_script.py"))
def test_workflow_joblist_with_files(self): with TestAreaContext("python/job_queue/workflow_joblist") as work_area: WorkflowCommon.createErtScriptsJob() WorkflowCommon.createExternalDumpJob() WorkflowCommon.createInternalFunctionJob() joblist = WorkflowJoblist() joblist.addJobFromFile("DUMP_JOB", "dump_job") joblist.addJobFromFile("SELECT_CASE_JOB", "select_case_job") joblist.addJobFromFile("SUBTRACT_SCRIPT_JOB", "subtract_script_job") self.assertTrue("DUMP_JOB" in joblist) self.assertTrue("SELECT_CASE_JOB" in joblist) self.assertTrue("SUBTRACT_SCRIPT_JOB" in joblist) self.assertFalse((joblist["DUMP_JOB"]).isInternal()) self.assertTrue((joblist["SELECT_CASE_JOB"]).isInternal()) self.assertTrue((joblist["SUBTRACT_SCRIPT_JOB"]).isInternal())
def test_arguments(self): with TestAreaContext("python/job_queue/workflow_job"): WorkflowCommon.createInternalFunctionJob() config = self._alloc_config() job = self._alloc_from_file("PRINTF", config, "printf_job") self.assertEqual(job.minimumArgumentCount(), 4) self.assertEqual(job.maximumArgumentCount(), 5) self.assertEqual(job.argumentTypes(), [str, int, float, bool, str]) self.assertTrue(job.run(None, ["x %d %f %d", 1, 2.5, True])) self.assertTrue(job.run(None, ["x %d %f %d %s", 1, 2.5, True, "y"])) with self.assertRaises(UserWarning): # Too few arguments job.run(None, ["x %d %f", 1, 2.5]) with self.assertRaises(UserWarning): # Too many arguments job.run(None, ["x %d %f %d %s", 1, 2.5, True, "y", "nada"])
def test_compare(self): with TestAreaContext("python/job_queue/workflow_job") as work_area: WorkflowCommon.createInternalFunctionJob() parser = WorkflowJob.configParser() with self.assertRaises(IOError): workflow_job = WorkflowJob.fromFile("no/such/file") workflow_job = WorkflowJob.fromFile("compare_job", name="COMPARE", parser=parser) self.assertEqual(workflow_job.name(), "COMPARE") result = workflow_job.run(None, ["String", "string"]) self.assertNotEqual(result, 0) result = workflow_job.run(None, ["String", "String"]) # result is returned as c_void_p -> automatic conversion to None if value is 0 self.assertIsNone(result) workflow_job = WorkflowJob.fromFile("compare_job") self.assertEqual(workflow_job.name(), "compare_job")