Exemplo n.º 1
0
    def test_ert_script_from_file(self):
        with TestAreaContext("python/job_queue/ert_script") as work_area:
            ErtScriptTest.createScripts()

            script_object = ErtScript.loadScriptFromFile("subtract_script.py")

            script = script_object("ert")
            result = script.initializeAndRun([int, int], ["1", "2"])
            self.assertEqual(result, -1)


            # with self.assertRaises(ErtScriptError):
            self.assertIsNone(ErtScript.loadScriptFromFile("syntax_error_script.py"))
            self.assertIsNone(ErtScript.loadScriptFromFile("import_error_script.py"))
            self.assertIsNone(ErtScript.loadScriptFromFile("empty_script.py"))
Exemplo n.º 2
0
    def isPlugin(self):
        """ @rtype: bool """
        if self.isInternalScript():
            script_obj = ErtScript.loadScriptFromFile(self.getInternalScriptPath())
            return script_obj is not None and issubclass(script_obj, ErtPlugin)

        return False
Exemplo n.º 3
0
    def test_ert_script_from_file(self):
        with TestAreaContext("python/job_queue/ert_script") as work_area:
            ErtScriptTest.createScripts()

            script_object = ErtScript.loadScriptFromFile("subtract_script.py")

            script = script_object("ert")
            result = script.initializeAndRun([int, int], ["1", "2"])
            self.assertEqual(result, -1)

            # with self.assertRaises(ErtScriptError):
            self.assertIsNone(
                ErtScript.loadScriptFromFile("syntax_error_script.py"))
            self.assertIsNone(
                ErtScript.loadScriptFromFile("import_error_script.py"))
            self.assertIsNone(ErtScript.loadScriptFromFile("empty_script.py"))
Exemplo n.º 4
0
    def run(self, ert, arguments, verbose=False):
        """
        @type ert: ert.enkf.enkf_main.EnKFMain
        @type arguments: list of str
        @type verbose: bool
        @rtype: ctypes.c_void_p
        """

        min_arg = self.minimumArgumentCount()
        if min_arg > 0 and len(arguments) < min_arg:
            raise UserWarning("The job: %s requires at least %d arguments, %d given." % (self.name(), min_arg, len(arguments)))

        max_arg = self.maximumArgumentCount()
        if 0 < max_arg < len(arguments):
            raise UserWarning("The job: %s can only have %d arguments, %d given." % (self.name(), max_arg, len(arguments)))


        if self.isInternalScript():
            script_obj = ErtScript.loadScriptFromFile(self.getInternalScriptPath())
            self.__script = script_obj(ert)
            return self.__script.initializeAndRun(self.argumentTypes(), arguments, verbose=verbose)

        elif self.isInternal() and not self.isInternalScript():
            self.__script = FunctionErtScript(ert, self.functionName(), self.argumentTypes(), argument_count=len(arguments))
            return self.__script.initializeAndRun(self.argumentTypes(), arguments, verbose=verbose)

        elif not self.isInternal():
            self.__script = ExternalErtScript(ert, self.executable())
            return self.__script.initializeAndRun(self.argumentTypes(), arguments, verbose=verbose)

        else:
            raise UserWarning("Unknown script type!")
Exemplo n.º 5
0
    def isPlugin(self):
        """ @rtype: bool """
        if self.isInternalScript():
            script_obj = ErtScript.loadScriptFromFile(
                self.getInternalScriptPath())
            return script_obj is not None and issubclass(script_obj, ErtPlugin)

        return False
Exemplo n.º 6
0
    def getPlugin(self, ert, job_name):
        mda_es = self.createSharePath("workflows/jobs/internal-gui/config/%s" % job_name)

        ert.getWorkflowList().addJob("TEST_MDA_ES", mda_es)
        plugin_job = ert.getWorkflowList().getJob("TEST_MDA_ES")

        self.assertIsNotNone(plugin_job)

        script_obj = ErtScript.loadScriptFromFile(plugin_job.getInternalScriptPath())
        script = script_obj(ert)
        return script
Exemplo n.º 7
0
    def getPlugin(self, ert, job_name):
        mda_es = self.createSharePath("workflows/jobs/internal-gui/config/%s" %
                                      job_name)

        ert.getWorkflowList().addJob("TEST_MDA_ES", mda_es)
        plugin_job = ert.getWorkflowList().getJob("TEST_MDA_ES")

        self.assertIsNotNone(plugin_job)

        script_obj = ErtScript.loadScriptFromFile(
            plugin_job.getInternalScriptPath())
        script = script_obj(ert)
        return script
Exemplo n.º 8
0
 def getScript(self, plugin_job):
     script_obj = ErtScript.loadScriptFromFile(plugin_job.getInternalScriptPath())
     script = script_obj(self.ert())
     return script
Exemplo n.º 9
0
 def __loadPlugin(self):
     """ @rtype: ErtPlugin """
     script_obj = ErtScript.loadScriptFromFile(self.__workflow_job.getInternalScriptPath())
     script = script_obj(self.__ert)
     return script
Exemplo n.º 10
0
 def getScript(self, plugin_job):
     script_obj = ErtScript.loadScriptFromFile(
         plugin_job.getInternalScriptPath())
     script = script_obj(self.ert())
     return script