Salome HOME
updated copyright message
[modules/yacs.git] / src / evalyfx_swig / test2.py
1 # Copyright (C) 2015-2023  CEA/DEN, EDF R&D
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 # bug revealed by otgui on 8/2/16. Several lock/unlock session. test1.xml is Cogeneration.xml.
21
22 def buildScheme(fname):
23     import SALOMERuntime
24     import loader
25     SALOMERuntime.RuntimeSALOME.setRuntime()
26     r=SALOMERuntime.getSALOMERuntime()
27     p0=r.createProc("run")
28     #
29     p=r.createBloc("toto")
30     p0.edAddChild(p)
31     #
32     cont=p0.createContainer("MyWonderfulContainer","Salome")
33     td=p0.createType("double","double")
34     n0=r.createScriptNode("Salome","PyScript0")
35     p.edAddChild(n0)
36     q=n0.edAddInputPort("q",td)
37     ep=n0.edAddOutputPort("ep",td)
38     n0.setScript("ep=1./(4.-q)") # <- force division by 0
39     n0.setExecutionMode("remote")
40     n0.setContainer(cont)
41     p0.saveSchema(fname)
42     pass
43
44 fname="test2.xml"
45 import evalyfx
46 session=evalyfx.YACSEvalSession()
47 session.launch()
48 buildScheme(fname)
49 efx=evalyfx.YACSEvalYFX.BuildFromFile(fname)
50 #efx.setParallelizeStatus(False)
51 efx.getParams().setStopASAPAfterErrorStatus(False)
52 inps=efx.getFreeInputPorts()
53 assert(len(inps)==1)
54 outps=efx.getFreeOutputPorts()
55 inps[0].setSequenceOfValuesToEval([1.,2.,3.,4.,5.,6.])
56 efx.lockPortsForEvaluation(inps,outps)
57 rss=efx.giveResources()
58 rss[0][0].setWantedMachine("localhost")
59 assert(rss.isInteractive())
60 a,b=efx.run(session)
61 assert(efx.getStatusOfRunStr()=='SOME_SAMPLES_FAILED_AND_ALL_OF_THEM_FAILED_DETERMINISTICALLY')
62 c,d=efx.getResultsInCaseOfFailure()
63 assert(d==[0,1,2,4,5])# case 3 is not in !
64 assert(len(c)==1)
65 c=c[0]
66 for f,g in zip(c,[0.3333333333333333,0.5,1.0,-1.0,-0.5]):
67     assert(abs(f-g)<1e-12)
68     pass
69 st=efx.getErrorDetailsInCaseOfFailure()
70 assert("NODE = toto.PyScript0" in st)
71 assert("float division by zero" in st)