return result;
}
+ if(!result->lastError().empty())
+ {
+ _lastError = result->lastError();
+ delete result;
+ result = nullptr;
+ return result;
+ }
+
if(!result->launch())
{
_lastError = "Failed to submit job.\n";
for(const py2cpp::PyPtr& obj : pyobjResult)
CPPUNIT_ASSERT(obj.repr() == "['object which needs pickel protocol']");
delete myJob;
+
+ // test a case of error
+ std::string wrongScript = "wrong 'script";
+ ydefx::PyStudyFunction wrongStudy;
+ wrongStudy.loadString(wrongScript);
+ CPPUNIT_ASSERT(!wrongStudy.isValid());
+ myJob = l.submitMonoPyJob(wrongStudy, sample, jobParams);
+ CPPUNIT_ASSERT(myJob == nullptr);
+ CPPUNIT_ASSERT(l.lastError().find("SyntaxError") != std::string::npos);
}
Py_Finalize();
}
The result directory will contain all the files needed for a launch and a
job is created but not launched.
"""
+ self._check(script,sample)
self.sample = sample
self.params = params
self.params.salome_parameters.job_type = self.jobType()
extra_files.extend(inputFiles)
return schema_path, extra_files
+ def _check(self, script, sample):
+ "Raise StudyUseException if the sample does not match with the sample."
+ script_params = script.getInputNames()
+ sample_inputs = sample.getInputNames()
+ if len(script_params) < 1:
+ raise StudyUseException("The study function should have at least one parameter. None found.")
+ if len(script_params) != len(sample_inputs):
+ m="The study function should have the same number of parameters as the input variables in the sample ({} != {})."
+ raise StudyUseException(m.format(len(script_params), len(sample_inputs)))
+ for nm in script_params:
+ if nm not in sample_inputs:
+ raise StudyUseException("Parameter {} not found in the sample.".format(nm))
+
### Deprecated!!!!
def dumpJob(result_directory, jobString):
"""
def test_availableResources(self):
import pydefx
lr = pydefx.configuration.availableResources()
- self.assertIn('localhost', lr)
+ self.assertIn('localhost', lr)
+
+ def test_invalid_study(self):
+ import pydefx
+ myParams = pydefx.Parameters()
+ myParams.configureResource("localhost")
+ myScript = pydefx.PyScript()
+ myStudy = pydefx.PyStudy()
+
+ myScript.loadString("wrong 'script")
+ mySample = pydefx.Sample([],[])
+ try:
+ myStudy.createNewJob(myScript, mySample, myParams)
+ self.fail("Excpected pydefx.pyscript.PyScriptException!")
+ except pydefx.pyscript.PyScriptException:
+ pass
+ except pydefx.studyexception.StudyException:
+ pass
+
+ script="""
+def _exec():
+ x=5
+ return x
+"""
+ myScript.loadString(script)
+ try:
+ myStudy.createNewJob(myScript, mySample, myParams)
+ self.fail("Excpected pydefx.studyexception.StudyUseException!")
+ except pydefx.studyexception.StudyException:
+ pass
+
+ script="""
+def _exec(a):
+ x=5
+ return x
+"""
+ myScript.loadString(script)
+ try:
+ myStudy.createNewJob(myScript, mySample, myParams)
+ self.fail("Excpected pydefx.studyexception.StudyUseException!")
+ except pydefx.studyexception.StudyException:
+ pass
+
+ mySample = pydefx.Sample(["b"],[])
+ try:
+ myStudy.createNewJob(myScript, mySample, myParams)
+ self.fail("Excpected pydefx.studyexception.StudyUseException!")
+ except pydefx.studyexception.StudyException:
+ pass
if __name__ == '__main__':
unittest.main()