Esempio n. 1
0
    def test_workflow_success(self):
        with TestAreaContext(
                "python/job_queue/workflow_runner_fast") as work_area:
            WorkflowCommon.createWaitJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("WAIT", "wait_job"))
            self.assertTrue(
                joblist.addJobFromFile("EXTERNAL_WAIT", "external_wait_job"))

            workflow = Workflow("fast_wait_workflow", joblist)

            self.assertEqual(len(workflow), 2)

            workflow_runner = WorkflowRunner(workflow,
                                             ert=None,
                                             context=SubstitutionList())

            self.assertFalse(workflow_runner.isRunning())

            workflow_runner.run()
            time.sleep(1)  # wait for workflow to start
            workflow_runner.wait()

            self.assertFileExists("wait_started_0")
            self.assertFileDoesNotExist("wait_cancelled_0")
            self.assertFileExists("wait_finished_0")

            self.assertFileExists("wait_started_1")
            self.assertFileDoesNotExist("wait_cancelled_1")
            self.assertFileExists("wait_finished_1")

            self.assertTrue(workflow_runner.workflowResult())
Esempio n. 2
0
    def test_workflow_success(self):
        with TestAreaContext("python/job_queue/workflow_runner_fast") as work_area:
            WorkflowCommon.createWaitJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("WAIT", "wait_job"))
            self.assertTrue(joblist.addJobFromFile("EXTERNAL_WAIT", "external_wait_job"))

            workflow = Workflow("fast_wait_workflow", joblist)

            self.assertEqual(len(workflow), 2)


            workflow_runner = WorkflowRunner(workflow, ert=None, context=SubstitutionList())

            self.assertFalse(workflow_runner.isRunning())

            workflow_runner.run()
            time.sleep(1) # wait for workflow to start
            workflow_runner.wait()

            self.assertFileExists("wait_started_0")
            self.assertFileDoesNotExist("wait_cancelled_0")
            self.assertFileExists("wait_finished_0")

            self.assertFileExists("wait_started_1")
            self.assertFileDoesNotExist("wait_cancelled_1")
            self.assertFileExists("wait_finished_1")

            self.assertTrue(workflow_runner.workflowResult())
Esempio n. 3
0
    def test_read_internal_function(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()
            WorkflowCommon.createErtScriptsJob()

            config = alloc_config()
            workflow_job = 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 = 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"))
Esempio n. 4
0
    def test_run_internal_script(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createErtScriptsJob()

            config = alloc_config()
            job = alloc_from_file("SUBTRACT", config, "subtract_script_job")

            result = job.run(None, ["1", "2"])

            self.assertEqual(result, -1)
Esempio n. 5
0
    def test_run_internal_script(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createErtScriptsJob()

            config = alloc_config()
            job = alloc_from_file("SUBTRACT", config, "subtract_script_job")

            result = job.run(None, ["1", "2"])

            self.assertEqual(result, -1)
Esempio n. 6
0
    def createScripts():
        WorkflowCommon.createErtScriptsJob()

        with open("syntax_error_script.py", "w") as f:
            f.write("from ert.enkf not_legal_syntax ErtScript\n")

        with open("import_error_script.py", "w") as f:
            f.write("from ert.enkf import DoesNotExist\n")

        with open("empty_script.py", "w") as f:
            f.write("from ert.enkf import ErtScript\n")
Esempio n. 7
0
    def createScripts():
        WorkflowCommon.createErtScriptsJob()

        with open("syntax_error_script.py", "w") as f:
            f.write("from ert.enkf not_legal_syntax ErtScript\n")

        with open("import_error_script.py", "w") as f:
            f.write("from ert.enkf import DoesNotExist\n")

        with open("empty_script.py", "w") as f:
            f.write("from ert.enkf import ErtScript\n")
Esempio n. 8
0
    def test_compare(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()

            config = alloc_config()
            workflow_job = alloc_from_file("COMPARE", config, "compare_job")

            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)
Esempio n. 9
0
    def test_run_external_job(self):

        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createExternalDumpJob()

            config = alloc_config()
            job = alloc_from_file("DUMP", config, "dump_job")

            self.assertFalse(job.isInternal())

            self.assertIsNone(job.run(None, ["test", "text"]))

            with open("test", "r") as f:
                self.assertEqual(f.read(), "text")
Esempio n. 10
0
    def test_run_external_job(self):

        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createExternalDumpJob()

            config = alloc_config()
            job = alloc_from_file("DUMP", config, "dump_job")

            self.assertFalse(job.isInternal())

            self.assertIsNone(job.run(None, ["test", "text"]))

            with open("test", "r") as f:
                self.assertEqual(f.read(), "text")
Esempio n. 11
0
    def test_arguments(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()

            config = alloc_config()
            job = 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 %s", 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"])
Esempio n. 12
0
    def test_workflow_thread_cancel_ert_script(self):
        with TestAreaContext("python/job_queue/workflow_runner_ert_script") as work_area:
            WorkflowCommon.createWaitJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("WAIT", "wait_job"))
            self.assertTrue("WAIT" in joblist)

            workflow = Workflow("wait_workflow", joblist)

            self.assertEqual(len(workflow), 3)


            workflow_runner = WorkflowRunner(workflow)

            self.assertFalse(workflow_runner.isRunning())

            workflow_runner.run()

            self.assertIsNone(workflow_runner.workflowResult())

            time.sleep(1) # wait for workflow to start
            self.assertTrue(workflow_runner.isRunning())
            self.assertFileExists("wait_started_0")

            time.sleep(1) # wait for first job to finish

            workflow_runner.cancel()
            time.sleep(1) # wait for cancel to take effect
            self.assertFileExists("wait_finished_0")


            self.assertFileExists("wait_started_1")
            self.assertFileExists("wait_cancelled_1")
            self.assertFileDoesNotExist("wait_finished_1")

            self.assertTrue(workflow_runner.isCancelled())

            workflow_runner.wait() # wait for runner to complete

            self.assertFileDoesNotExist("wait_started_2")
            self.assertFileDoesNotExist("wait_cancelled_2")
            self.assertFileDoesNotExist("wait_finished_2")
Esempio n. 13
0
    def test_workflow_thread_cancel_ert_script(self):
        with TestAreaContext(
                "python/job_queue/workflow_runner_ert_script") as work_area:
            WorkflowCommon.createWaitJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("WAIT", "wait_job"))
            self.assertTrue("WAIT" in joblist)

            workflow = Workflow("wait_workflow", joblist)

            self.assertEqual(len(workflow), 3)

            workflow_runner = WorkflowRunner(workflow)

            self.assertFalse(workflow_runner.isRunning())

            workflow_runner.run()

            self.assertIsNone(workflow_runner.workflowResult())

            time.sleep(1)  # wait for workflow to start
            self.assertTrue(workflow_runner.isRunning())
            self.assertFileExists("wait_started_0")

            time.sleep(1)  # wait for first job to finish

            workflow_runner.cancel()
            time.sleep(1)  # wait for cancel to take effect
            self.assertFileExists("wait_finished_0")

            self.assertFileExists("wait_started_1")
            self.assertFileExists("wait_cancelled_1")
            self.assertFileDoesNotExist("wait_finished_1")

            self.assertTrue(workflow_runner.isCancelled())

            workflow_runner.wait()  # wait for runner to complete

            self.assertFileDoesNotExist("wait_started_2")
            self.assertFileDoesNotExist("wait_cancelled_2")
            self.assertFileDoesNotExist("wait_finished_2")
Esempio n. 14
0
    def test_arguments(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()

            config = alloc_config()
            job = 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 %s", 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"])
Esempio n. 15
0
    def test_workflow_run(self):
        with TestAreaContext("python/job_queue/workflow") as work_area:
            WorkflowCommon.createExternalDumpJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("DUMP", "dump_job"))
            self.assertTrue("DUMP" in joblist)

            workflow = Workflow("dump_workflow", joblist)

            self.assertTrue(len(workflow), 2)

            context = SubstitutionList()
            context.addItem("<PARAM>", "text")

            self.assertTrue(workflow.run(None, verbose=True, context=context))

            with open("dump1", "r") as f:
                self.assertEqual(f.read(), "dump_text_1")

            with open("dump2", "r") as f:
                self.assertEqual(f.read(), "dump_text_2")
Esempio n. 16
0
    def test_workflow_run(self):
        with TestAreaContext("python/job_queue/workflow") as work_area:
            WorkflowCommon.createExternalDumpJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("DUMP", "dump_job"))
            self.assertTrue("DUMP" in joblist)

            workflow = Workflow("dump_workflow", joblist)

            self.assertTrue(len(workflow), 2)

            context = SubstitutionList()
            context.addItem("<PARAM>", "text")

            self.assertTrue(workflow.run(None, verbose=True, context=context))

            with open("dump1", "r") as f:
                self.assertEqual(f.read(), "dump_text_1")

            with open("dump2", "r") as f:
                self.assertEqual(f.read(), "dump_text_2")
Esempio n. 17
0
    def test_read_internal_function(self):
        with TestAreaContext("python/job_queue/workflow_job") as work_area:
            WorkflowCommon.createInternalFunctionJob()
            WorkflowCommon.createErtScriptsJob()

            config = alloc_config()
            workflow_job = 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 = 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"))
Esempio n. 18
0
    def test_workflow(self):
        with TestAreaContext("python/job_queue/workflow") as work_area:
            WorkflowCommon.createExternalDumpJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("DUMP", "dump_job"))

            with self.assertRaises(UserWarning):
                joblist.addJobFromFile("KNOCK", "knock_job")

            self.assertTrue("DUMP" in joblist)

            workflow = Workflow("dump_workflow", joblist)

            self.assertEqual(len(workflow), 2)

            job, args = workflow[0]
            self.assertEqual(job, joblist["DUMP"])
            self.assertEqual(args[0], "dump1")
            self.assertEqual(args[1], "dump_text_1")

            job, args = workflow[1]
            self.assertEqual(job, joblist["DUMP"])
Esempio n. 19
0
    def test_workflow(self):
        with TestAreaContext("python/job_queue/workflow") as work_area:
            WorkflowCommon.createExternalDumpJob()

            joblist = WorkflowJoblist()
            self.assertTrue(joblist.addJobFromFile("DUMP", "dump_job"))

            with self.assertRaises(UserWarning):
                joblist.addJobFromFile("KNOCK", "knock_job")

            self.assertTrue("DUMP" in joblist)


            workflow = Workflow("dump_workflow", joblist)

            self.assertEqual(len(workflow), 2)

            job, args = workflow[0]
            self.assertEqual(job, joblist["DUMP"])
            self.assertEqual(args[0], "dump1")
            self.assertEqual(args[1], "dump_text_1")

            job, args = workflow[1]
            self.assertEqual(job, joblist["DUMP"])
Esempio n. 20
0
    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())
Esempio n. 21
0
    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())