Salome HOME
Test to check YACS capacity to deal with old XML files
[modules/yacs.git] / src / yacsloader_swig / Test / testSaveLoadRun.py
1 # Copyright (C) 2006-2019  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 import unittest
21 import pilot
22 import SALOMERuntime
23 import loader
24
25 import datetime
26
27 class TestSaveLoadRun(unittest.TestCase):
28   def setUp(self):
29     SALOMERuntime.RuntimeSALOME.setRuntime()
30     self.r=SALOMERuntime.getSALOMERuntime()
31     pass
32
33   def test0(self):
34     """First test of HP Container no loop here only the 3 sorts of python nodes (the Distributed is it still used and useful ?) """
35     fname="TestSaveLoadRun0.xml"
36     nbOfNodes=8
37     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
38     l=loader.YACSLoader()
39     p=self.r.createProc("prTest0")
40     td=p.createType("double","double")
41     ti=p.createType("int","int")
42     cont=p.createContainer("gg","HPSalome")
43     cont.setSizeOfPool(4)
44     cont.setProperty("name","localhost")
45     cont.setProperty("hostname","localhost")
46     script0="""
47 def ff(nb,dbg):
48     from math import cos
49     import datetime
50     
51     ref=datetime.datetime.now()
52     t=0. ; pas=1./float(nb)
53     for i in range(nb):
54         for j in range(nb):
55             x=j*pas
56             t+=1.+cos(1.*(x*3.14159))
57             pass
58         pass
59     print("coucou from script0-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
60     return t
61 """
62     script1="""
63 from math import cos
64 import datetime
65 ref=datetime.datetime.now()
66 o2=0. ; pas=1./float(i1)
67 for i in range(i1):
68   for j in range(i1):
69     x=j*pas
70     o2+=1.+cos(1.*(x*3.14159))
71     pass
72 print("coucou from script1-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
73 """
74     for i in range(nbOfNodes):
75       node0=self.r.createFuncNode("DistPython","node%i"%(i))
76       p.edAddChild(node0)
77       node0.setFname("ff")
78       node0.setContainer(cont)
79       node0.setScript(script0)
80       nb=node0.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
81       dbg=node0.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
82       out0=node0.edAddOutputPort("s",td)
83       #
84       nodeMiddle=self.r.createFuncNode("Salome","node%i_1"%(i))
85       p.edAddChild(nodeMiddle)
86       p.edAddCFLink(node0,nodeMiddle)
87       nodeMiddle.setFname("ff")
88       nodeMiddle.setContainer(cont)
89       nodeMiddle.setScript(script0)
90       nb=nodeMiddle.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
91       dbg=nodeMiddle.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
92       out0=nodeMiddle.edAddOutputPort("s",td)
93       nodeMiddle.setExecutionMode("remote")
94       #
95       nodeEnd=self.r.createScriptNode("Salome","node%i_2"%(i+1))
96       p.edAddChild(nodeEnd)
97       p.edAddCFLink(nodeMiddle,nodeEnd)
98       nodeEnd.setContainer(cont)
99       nodeEnd.setScript(script1)
100       i1=nodeEnd.edAddInputPort("i1",ti) ; i1.edInitInt(sqrtOfNumberOfTurn)
101       dbg=nodeEnd.edAddInputPort("dbg",ti) ; dbg.edInitInt(i)
102       o2=nodeEnd.edAddOutputPort("o2",td)
103       nodeEnd.setExecutionMode("remote")
104       pass
105     p.saveSchema(fname)
106     p=l.load(fname)
107     ex=pilot.ExecutorSwig()
108     self.assertEqual(p.getState(),pilot.READY)
109     st=datetime.datetime.now()
110     # 1st exec
111     ex.RunW(p,0)
112     print("Time spend of test0 to run 1st %s"%(str(datetime.datetime.now()-st)))
113     self.assertEqual(p.getState(),pilot.DONE)
114     # 2nd exec using the same already launched remote python interpreters
115     st=datetime.datetime.now()
116     ex.RunW(p,0)
117     print("Time spend of test0 to run 2nd %s"%(str(datetime.datetime.now()-st)))
118     self.assertEqual(p.getState(),pilot.DONE)
119     # 3rd exec using the same already launched remote python interpreters
120     st=datetime.datetime.now()
121     ex.RunW(p,0)
122     print("Time spend of test0 to run 3rd %s"%(str(datetime.datetime.now()-st)))
123     self.assertEqual(p.getState(),pilot.DONE)
124     pass
125
126   def test1(self):
127     """ HP Container again like test0 but the initialization key of HPContainer is used here."""
128     fname="TestSaveLoadRun1.xml"
129     nbOfNodes=8
130     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
131     l=loader.YACSLoader()
132     p=self.r.createProc("prTest1")
133     td=p.createType("double","double")
134     ti=p.createType("int","int")
135     cont=p.createContainer("gg","HPSalome")
136     cont.setSizeOfPool(4)
137     cont.setProperty("InitializeScriptKey","aa=123.456")
138     cont.setProperty("name","localhost")
139     cont.setProperty("hostname","localhost")
140     script0="""
141 def ff(nb,dbg):
142     from math import cos
143     import datetime
144     
145     ref=datetime.datetime.now()
146     t=0. ; pas=1./float(nb)
147     for i in range(nb):
148         for j in range(nb):
149             x=j*pas
150             t+=1.+cos(1.*(x*3.14159))
151             pass
152         pass
153     print("coucou from script0-%i  -> %s"%(dbg,str(datetime.datetime.now()-ref)))
154     return t
155 """
156     # here in script1 aa is refered ! aa will exist thanks to HPCont Init Script
157     script1="""
158 from math import cos
159 import datetime
160 ref=datetime.datetime.now()
161 o2=0. ; pas=1./float(i1)
162 for i in range(i1):
163   for j in range(i1):
164     x=j*pas
165     o2+=1.+cos(1.*(x*3.14159))
166     pass
167 print("coucou %lf from script1-%i  -> %s"%(aa,dbg,str(datetime.datetime.now()-ref)))
168 aa+=1.
169 """
170     #
171     for i in range(nbOfNodes):
172       nodeMiddle=self.r.createFuncNode("Salome","node%i_1"%(i)) # PyFuncNode remote
173       p.edAddChild(nodeMiddle)
174       nodeMiddle.setFname("ff")
175       nodeMiddle.setContainer(cont)
176       nodeMiddle.setScript(script0)
177       nb=nodeMiddle.edAddInputPort("nb",ti) ; nb.edInitInt(sqrtOfNumberOfTurn)
178       dbg=nodeMiddle.edAddInputPort("dbg",ti) ; dbg.edInitInt(i+1)
179       out0=nodeMiddle.edAddOutputPort("s",td)
180       nodeMiddle.setExecutionMode("remote")
181       #
182       nodeEnd=self.r.createScriptNode("Salome","node%i_2"%(i+1)) # PythonNode remote
183       p.edAddChild(nodeEnd)
184       p.edAddCFLink(nodeMiddle,nodeEnd)
185       nodeEnd.setContainer(cont)
186       nodeEnd.setScript(script1)
187       i1=nodeEnd.edAddInputPort("i1",ti) ; i1.edInitInt(sqrtOfNumberOfTurn)
188       dbg=nodeEnd.edAddInputPort("dbg",ti) ; dbg.edInitInt(i)
189       o2=nodeEnd.edAddOutputPort("o2",td)
190       nodeEnd.setExecutionMode("remote")
191       pass
192     #
193     p.saveSchema(fname)
194     p=l.load(fname)
195     self.assertEqual(p.edGetDirectDescendants()[0].getContainer().getProperty("InitializeScriptKey"),"aa=123.456")
196     # 1st exec
197     ex=pilot.ExecutorSwig()
198     self.assertEqual(p.getState(),pilot.READY)
199     st=datetime.datetime.now()
200     ex.RunW(p,0)
201     print("Time spend of test1 to 1st run %s"%(str(datetime.datetime.now()-st)))
202     self.assertEqual(p.getState(),pilot.DONE)
203     # 2nd exec
204     st=datetime.datetime.now()
205     ex.RunW(p,0)
206     print("Time spend of test1 to 2nd run %s"%(str(datetime.datetime.now()-st)))
207     self.assertEqual(p.getState(),pilot.DONE)
208     # 3rd exec
209     st=datetime.datetime.now()
210     ex.RunW(p,0)
211     print("Time spend of test1 to 3rd run %s"%(str(datetime.datetime.now()-st)))
212     self.assertEqual(p.getState(),pilot.DONE)
213     pass
214
215   def test2(self):
216     """ Test on HP Containers in foreach context."""
217     script0="""def ff():
218     global aa
219     print("%%lf - %%s"%%(aa,str(my_container)))
220     return 16*[%i],0
221 """
222     script1="""from math import cos
223 import datetime
224 ref=datetime.datetime.now()
225 o2=0. ; pas=1./float(i1)
226 for i in range(i1):
227   for j in range(i1):
228     x=j*pas
229     o2+=1.+cos(1.*(x*3.14159))
230     pass
231 print("coucou %lf from script  -> %s"%(aa,str(datetime.datetime.now()-ref)))
232 aa+=1.
233 o3=0
234 """
235     script2="""o9=sum(i8)
236 """
237     fname="TestSaveLoadRun2.xml"
238     nbOfNodes=8
239     sqrtOfNumberOfTurn=1000 # 3000 -> 3.2s/Node, 1000 -> 0.1s/Node
240     l=loader.YACSLoader()
241     p=self.r.createProc("prTest1")
242     td=p.createType("double","double")
243     ti=p.createType("int","int")
244     tdi=p.createSequenceTc("seqint","seqint",ti)
245     tdd=p.createSequenceTc("seqdouble","seqdouble",td)
246     cont=p.createContainer("gg","HPSalome")
247     cont.setSizeOfPool(4)
248     cont.setProperty("InitializeScriptKey","aa=123.456")
249     cont.setProperty("name","localhost")
250     cont.setProperty("hostname","localhost")
251     #
252     node0=self.r.createFuncNode("Salome","PyFunction0") # PyFuncNode remote
253     p.edAddChild(node0)
254     node0.setFname("ff")
255     node0.setContainer(cont)
256     node0.setScript(script0%(sqrtOfNumberOfTurn))
257     out0_0=node0.edAddOutputPort("o1",tdi)
258     out1_0=node0.edAddOutputPort("o2",ti)
259     node0.setExecutionMode("remote")
260     #
261     node1=self.r.createForEachLoop("node1",ti)
262     p.edAddChild(node1)
263     p.edAddCFLink(node0,node1)
264     p.edAddLink(out0_0,node1.edGetSeqOfSamplesPort())
265     node1.edGetNbOfBranchesPort().edInitInt(8)
266     #
267     node2=self.r.createScriptNode("Salome","PyScript3")
268     node1.edAddChild(node2)
269     node2.setContainer(cont)
270     node2.setScript(script1)
271     i1=node2.edAddInputPort("i1",ti)
272     p.edAddLink(node1.edGetSamplePort(),i1)
273     out0_2=node2.edAddOutputPort("o2",td)
274     out1_2=node2.edAddOutputPort("o3",ti)
275     node2.setExecutionMode("remote")
276     #
277     node3=self.r.createScriptNode("Salome","PyScript7")
278     p.edAddChild(node3)
279     node3.setScript(script2)
280     p.edAddCFLink(node1,node3)
281     i8=node3.edAddInputPort("i8",tdd)
282     o9=node3.edAddOutputPort("o9",td)
283     p.edAddLink(out0_2,i8)
284     #
285     p.saveSchema(fname)
286     p=l.load(fname)
287     o9=p.getChildByName("PyScript7").getOutputPort("o9")
288     self.assertTrue(len(p.edGetDirectDescendants()[1].getChildByName("PyScript3").getContainer().getProperty("InitializeScriptKey"))!=0)
289     # 1st exec
290     refExpected=16016013.514623128
291     ex=pilot.ExecutorSwig()
292     self.assertEqual(p.getState(),pilot.READY)
293     st=datetime.datetime.now()
294     ex.RunW(p,0)
295     print("Time spend of test2 to 1st run %s"%(str(datetime.datetime.now()-st)))
296     self.assertEqual(p.getState(),pilot.DONE)
297     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
298     # 2nd exec
299     st=datetime.datetime.now()
300     ex.RunW(p,0)
301     print("Time spend of test2 to 2nd run %s"%(str(datetime.datetime.now()-st)))
302     self.assertEqual(p.getState(),pilot.DONE)
303     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
304     # 3rd exec
305     st=datetime.datetime.now()
306     ex.RunW(p,0)
307     print("Time spend of test2 to 3rd run %s"%(str(datetime.datetime.now()-st)))
308     self.assertEqual(p.getState(),pilot.DONE)
309     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
310     pass
311
312   def test3(self):
313     """ Test that focuses on parallel load of containers."""
314     script0="""def ff():
315     global aa
316     print("%%lf - %%s"%%(aa,str(my_container)))
317     return 100*[%i],0
318 """
319     script1="""from math import cos
320 import datetime
321 ref=datetime.datetime.now()
322 o2=0. ; pas=1./float(i1)
323 for i in range(i1):
324   for j in range(i1):
325     x=j*pas
326     o2+=1.+cos(1.*(x*3.14159))
327     pass
328 print("coucou %lf from script  -> %s"%(aa,str(datetime.datetime.now()-ref)))
329 aa+=1.
330 o3=0
331 """
332     script2="""o9=sum(i8)
333 """
334     fname="TestSaveLoadRun3.xml"
335     nbOfNodes=8
336     sqrtOfNumberOfTurn=10
337     l=loader.YACSLoader()
338     p=self.r.createProc("prTest1")
339     td=p.createType("double","double")
340     ti=p.createType("int","int")
341     tdi=p.createSequenceTc("seqint","seqint",ti)
342     tdd=p.createSequenceTc("seqdouble","seqdouble",td)
343     cont=p.createContainer("gg","HPSalome")
344     cont.setSizeOfPool(8)
345     cont.setProperty("InitializeScriptKey","aa=123.456")
346     cont.setProperty("name","localhost")
347     cont.setProperty("hostname","localhost")
348     #
349     node0=self.r.createFuncNode("Salome","PyFunction0") # PyFuncNode remote
350     p.edAddChild(node0)
351     node0.setFname("ff")
352     node0.setContainer(cont)
353     node0.setScript(script0%(sqrtOfNumberOfTurn))
354     out0_0=node0.edAddOutputPort("o1",tdi)
355     out1_0=node0.edAddOutputPort("o2",ti)
356     node0.setExecutionMode("remote")
357     #
358     node1=self.r.createForEachLoop("node1",ti)
359     p.edAddChild(node1)
360     p.edAddCFLink(node0,node1)
361     p.edAddLink(out0_0,node1.edGetSeqOfSamplesPort())
362     node1.edGetNbOfBranchesPort().edInitInt(16)
363     #
364     node2=self.r.createScriptNode("Salome","PyScript3")
365     node1.edAddChild(node2)
366     node2.setContainer(cont)
367     node2.setScript(script1)
368     i1=node2.edAddInputPort("i1",ti)
369     p.edAddLink(node1.edGetSamplePort(),i1)
370     out0_2=node2.edAddOutputPort("o2",td)
371     out1_2=node2.edAddOutputPort("o3",ti)
372     node2.setExecutionMode("remote")
373     #
374     node3=self.r.createScriptNode("Salome","PyScript7")
375     p.edAddChild(node3)
376     node3.setScript(script2)
377     p.edAddCFLink(node1,node3)
378     i8=node3.edAddInputPort("i8",tdd)
379     o9=node3.edAddOutputPort("o9",td)
380     p.edAddLink(out0_2,i8)
381     #
382     p.saveSchema(fname)
383     p=l.load(fname)
384     o9=p.getChildByName("PyScript7").getOutputPort("o9")
385     self.assertTrue(len(p.edGetDirectDescendants()[1].getChildByName("PyScript3").getContainer().getProperty("InitializeScriptKey"))!=0)
386     # 1st exec
387     refExpected=11000.008377058712
388     ex=pilot.ExecutorSwig()
389     self.assertEqual(p.getState(),pilot.READY)
390     st=datetime.datetime.now()
391     ex.RunW(p,0)
392     print("Time spend of test3 to 1st run %s"%(str(datetime.datetime.now()-st)))
393     self.assertEqual(p.getState(),pilot.DONE)
394     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
395     # 2nd exec
396     st=datetime.datetime.now()
397     ex.RunW(p,0)
398     print("Time spend of test3 to 2nd run %s"%(str(datetime.datetime.now()-st)))
399     self.assertEqual(p.getState(),pilot.DONE)
400     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
401     # 3rd exec
402     st=datetime.datetime.now()
403     ex.RunW(p,0)
404     print("Time spend of test3 to 3rd run %s"%(str(datetime.datetime.now()-st)))
405     self.assertEqual(p.getState(),pilot.DONE)
406     self.assertAlmostEqual(refExpected,o9.getPyObj(),5)
407     pass
408   
409   def test4(self):
410     """Non regression test of multi pyScriptNode, pyFuncNode sharing the same HPContainer instance."""
411     fname="TestSaveLoadRun4.xml"
412     script1="""nb=7
413 ii=0
414 o1=nb*[None]
415 for i in range(nb):
416     tmp=(i+10)*[None]
417     for j in range(i+10):
418         tmp[j]=ii
419         ii+=1
420         pass
421     o1[i]=tmp
422     pass
423 """
424     l=loader.YACSLoader()
425     ex=pilot.ExecutorSwig()
426     p=self.r.createProc("pr")
427     cont=p.createContainer("gg","HPSalome")
428     cont.setSizeOfPool(10)
429     td=p.createType("int","int")
430     td2=p.createSequenceTc("seqint","seqint",td)
431     td3=p.createSequenceTc("seqintvec","seqintvec",td2)
432     node1=self.r.createScriptNode("","node1")
433     node1.setScript(script1)
434     o1=node1.edAddOutputPort("o1",td3)
435     p.edAddChild(node1)
436     #
437     node2=self.r.createForEachLoop("node2",td2)
438     p.edAddChild(node2)
439     p.edAddCFLink(node1,node2)
440     p.edAddLink(o1,node2.edGetSeqOfSamplesPort())
441     node2.edGetNbOfBranchesPort().edInitInt(2)
442     node20=self.r.createBloc("node20")
443     node2.edAddChild(node20)
444     node200=self.r.createForEachLoop("node200",td)
445     node20.edAddChild(node200)
446     node200.edGetNbOfBranchesPort().edInitInt(10)
447     p.edAddLink(node2.edGetSamplePort(),node200.edGetSeqOfSamplesPort())
448     node2000=self.r.createScriptNode("","node2000")
449     node2000.setContainer(cont)
450     node2000.setExecutionMode("remote")
451     node200.edAddChild(node2000)
452     i5=node2000.edAddInputPort("i5",td)
453     o6=node2000.edAddOutputPort("o6",td)
454     node2000.setScript("o6=2+i5")
455     p.edAddLink(node200.edGetSamplePort(),i5)
456     #
457     node3=self.r.createForEachLoop("node3",td2)
458     p.edAddChild(node3)
459     p.edAddCFLink(node2,node3)
460     p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
461     node3.edGetNbOfBranchesPort().edInitInt(2)
462     node30=self.r.createBloc("node30")
463     node3.edAddChild(node30)
464     node300=self.r.createForEachLoop("node300",td)
465     node30.edAddChild(node300)
466     node300.edGetNbOfBranchesPort().edInitInt(10)
467     p.edAddLink(node3.edGetSamplePort(),node300.edGetSeqOfSamplesPort())
468     node3000=self.r.createScriptNode("","node3000")
469     node3000.setContainer(cont)
470     node3000.setExecutionMode("remote")
471     node300.edAddChild(node3000)
472     i14=node3000.edAddInputPort("i14",td)
473     o15=node3000.edAddOutputPort("o15",td)
474     node3000.setScript("o15=3+i14")
475     p.edAddLink(node300.edGetSamplePort(),i14)
476     #
477     node4=self.r.createScriptNode("","node4")
478     node4.setScript("o9=i8")
479     p.edAddChild(node4)
480     i8=node4.edAddInputPort("i8",td3)
481     o9=node4.edAddOutputPort("o9",td3)
482     p.edAddCFLink(node3,node4)
483     p.edAddLink(o15,i8)
484     p.saveSchema(fname)
485     p=l.load(fname)
486     ex = pilot.ExecutorSwig()
487     self.assertEqual(p.getState(),pilot.READY)
488     ex.RunW(p,0)
489     self.assertEqual(p.getState(),pilot.DONE)
490     zeResu=p.getChildByName("node4").getOutputPort("o9").get()
491     self.assertEqual(zeResu,[[5,6,7,8,9,10,11,12,13,14],[15,16,17,18,19,20,21,22,23,24,25],[26,27,28,29,30,31,32,33,34,35,36,37],[38,39,40,41,42,43,44,45,46,47,48,49,50],[51,52,53,54,55,56,57,58,59,60,61,62,63,64],[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79], [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95]])
492     pass
493
494   def test5(self):
495     """Non regression test 2 of multi pyNode, pyFuncNode sharing the same HPContainer instance."""
496     fname="TestSaveLoadRun5.xml"
497     script1="""nb=7
498 ii=0
499 o1=nb*[None]
500 for i in range(nb):
501     tmp=(i+10)*[None]
502     for j in range(i+10):
503         tmp[j]=ii
504         ii+=1
505         pass
506     o1[i]=tmp
507     pass
508 """
509     l=loader.YACSLoader()
510     ex=pilot.ExecutorSwig()
511     p=self.r.createProc("pr")
512     cont=p.createContainer("gg","HPSalome")
513     cont.setSizeOfPool(10)
514     td=p.createType("int","int")
515     td2=p.createSequenceTc("seqint","seqint",td)
516     td3=p.createSequenceTc("seqintvec","seqintvec",td2)
517     node1=self.r.createScriptNode("","node1")
518     node1.setScript(script1)
519     o1=node1.edAddOutputPort("o1",td3)
520     p.edAddChild(node1)
521     #
522     node2=self.r.createForEachLoop("node2",td2)
523     p.edAddChild(node2)
524     p.edAddCFLink(node1,node2)
525     p.edAddLink(o1,node2.edGetSeqOfSamplesPort())
526     node2.edGetNbOfBranchesPort().edInitInt(2)
527     node20=self.r.createBloc("node20")
528     node2.edAddChild(node20)
529     node200=self.r.createForEachLoop("node200",td)
530     node20.edAddChild(node200)
531     node200.edGetNbOfBranchesPort().edInitInt(10)
532     p.edAddLink(node2.edGetSamplePort(),node200.edGetSeqOfSamplesPort())
533     node2000=self.r.createFuncNode("Salome","node2000")
534     node2000.setFname("ff")
535     node2000.setContainer(cont)
536     node2000.setExecutionMode("remote")
537     node200.edAddChild(node2000)
538     i5=node2000.edAddInputPort("i5",td)
539     o6=node2000.edAddOutputPort("o6",td)
540     node2000.setScript("def ff(x):\n  return 2+x")
541     p.edAddLink(node200.edGetSamplePort(),i5)
542     #
543     node3=self.r.createForEachLoop("node3",td2)
544     p.edAddChild(node3)
545     p.edAddCFLink(node2,node3)
546     p.edAddLink(o6,node3.edGetSeqOfSamplesPort())
547     node3.edGetNbOfBranchesPort().edInitInt(2)
548     node30=self.r.createBloc("node30")
549     node3.edAddChild(node30)
550     node300=self.r.createForEachLoop("node300",td)
551     node30.edAddChild(node300)
552     node300.edGetNbOfBranchesPort().edInitInt(10)
553     p.edAddLink(node3.edGetSamplePort(),node300.edGetSeqOfSamplesPort())
554     node3000=self.r.createFuncNode("Salome","node3000")
555     node3000.setFname("ff")
556     node3000.setContainer(cont)
557     node3000.setExecutionMode("remote")
558     node300.edAddChild(node3000)
559     i14=node3000.edAddInputPort("i14",td)
560     o15=node3000.edAddOutputPort("o15",td)
561     node3000.setScript("def ff(x):\n  return 3+x")
562     p.edAddLink(node300.edGetSamplePort(),i14)
563     #
564     node4=self.r.createScriptNode("","node4")
565     node4.setScript("o9=i8")
566     p.edAddChild(node4)
567     i8=node4.edAddInputPort("i8",td3)
568     o9=node4.edAddOutputPort("o9",td3)
569     p.edAddCFLink(node3,node4)
570     p.edAddLink(o15,i8)
571     p.saveSchema(fname)
572     p=l.load(fname)
573     ex = pilot.ExecutorSwig()
574     self.assertEqual(p.getState(),pilot.READY)
575     ex.RunW(p,0)
576     self.assertEqual(p.getState(),pilot.DONE)
577     zeResu=p.getChildByName("node4").getOutputPort("o9").get()
578     self.assertEqual(zeResu,[[5,6,7,8,9,10,11,12,13,14],[15,16,17,18,19,20,21,22,23,24,25],[26,27,28,29,30,31,32,33,34,35,36,37],[38,39,40,41,42,43,44,45,46,47,48,49,50],[51,52,53,54,55,56,57,58,59,60,61,62,63,64],[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79], [80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95]])
579     pass
580
581   def test6(self):
582     fname="test6.xml"
583     p=self.r.createProc("prTest0")
584     td=p.createType("double","double")
585     ti=p.createType("int","int")
586     tsi=p.createSequenceTc("seqint","seqint",ti)
587     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
588     n0=self.r.createScriptNode("","n0")
589     o0=n0.edAddOutputPort("o0",tsi)
590     n0.setScript("o0=[3,6,8,9,-2,5]")
591     p.edAddChild(n0)
592     n1=self.r.createForEachLoop("n1",ti)
593     n10=self.r.createScriptNode("","n10")
594     n1.edAddChild(n10)
595     n10.setScript("o2=2*i1")
596     i1=n10.edAddInputPort("i1",ti)
597     o2=n10.edAddOutputPort("o2",ti)
598     p.edAddChild(n1)
599     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
600     p.edAddLink(n1.edGetSamplePort(),i1)
601     p.edAddCFLink(n0,n1)
602     n1.edGetNbOfBranchesPort().edInitPy(1)
603     n2=self.r.createScriptNode("","n2")
604     n2.setScript("o4=i3")
605     i3=n2.edAddInputPort("i3",tsi)
606     o4=n2.edAddOutputPort("o4",tsi)
607     n2.setScript("o4=i3")
608     p.edAddChild(n2)
609     p.edAddCFLink(n1,n2)
610     p.edAddLink(o2,i3)
611     p.saveSchema(fname)
612     #
613     l=loader.YACSLoader()
614     p=l.load(fname)
615     n1=p.getChildByName("n1")
616     ex=pilot.ExecutorSwig()
617     #
618     ex.RunW(p,0)
619     #
620     self.assertEqual(n1.getState(),pilot.DONE)
621     n1.edGetSeqOfSamplesPort().getPyObj()
622     a,b,c=n1.getPassedResults(ex)
623     self.assertEqual(a,list(range(6)))
624     self.assertEqual([elt.getPyObj() for elt in b],[[6, 12, 16, 18, -4, 10]])
625     self.assertEqual(c,['n10_o2_interceptor'])
626     pass
627
628   def test7(self):
629     fname="test7.xml"
630     p=self.r.createProc("prTest1")
631     cont=p.createContainer("gg","Salome")
632     cont.setProperty("name","localhost")
633     cont.setProperty("hostname","localhost")
634     cont.setProperty("type","multi")
635     td=p.createType("double","double")
636     ti=p.createType("int","int")
637     tsi=p.createSequenceTc("seqint","seqint",ti)
638     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
639     n0=self.r.createScriptNode("","n0")
640     o0=n0.edAddOutputPort("o0",tsi)
641     n0.setScript("o0=[3,6,8,9,-2,5]")
642     p.edAddChild(n0)
643     n1=self.r.createForEachLoop("n1",ti)
644     n10=self.r.createScriptNode("","n10")
645     n10.setExecutionMode("remote")
646     n10.setContainer(cont)
647     n1.edAddChild(n10)
648     n10.setScript("""
649 import time
650 if i1==9:
651   time.sleep(2)
652   raise Exception("Simulated error !")
653 else:
654   o2=2*i1
655 """)
656     i1=n10.edAddInputPort("i1",ti)
657     o2=n10.edAddOutputPort("o2",ti)
658     p.edAddChild(n1)
659     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
660     p.edAddLink(n1.edGetSamplePort(),i1)
661     p.edAddCFLink(n0,n1)
662     n1.edGetNbOfBranchesPort().edInitPy(1)
663     n2=self.r.createScriptNode("","n2")
664     n2.setScript("o4=i3")
665     i3=n2.edAddInputPort("i3",tsi)
666     o4=n2.edAddOutputPort("o4",tsi)
667     n2.setScript("o4=i3")
668     p.edAddChild(n2)
669     p.edAddCFLink(n1,n2)
670     p.edAddLink(o2,i3)
671     p.saveSchema(fname)
672     #
673     l=loader.YACSLoader()
674     p=l.load(fname)
675     n1=p.getChildByName("n1")
676     ex=pilot.ExecutorSwig()
677     #
678     ex.RunW(p,0)
679     #
680     self.assertEqual(n1.getState(),pilot.FAILED)
681     n1.edGetSeqOfSamplesPort().getPyObj()
682     a,b,c=n1.getPassedResults(ex)
683     self.assertEqual(a,list(range(3)))
684     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16]])
685     self.assertEqual(c,['n10_o2_interceptor'])
686     pass
687
688   def test8(self):
689     from datetime import datetime
690     fname="test8.xml"
691     p=self.r.createProc("prTest2")
692     cont=p.createContainer("gg","Salome")
693     cont.setProperty("name","localhost")
694     cont.setProperty("hostname","localhost")
695     cont.setProperty("type","multi")
696     td=p.createType("double","double")
697     ti=p.createType("int","int")
698     tsi=p.createSequenceTc("seqint","seqint",ti)
699     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
700     n0=self.r.createScriptNode("","n0")
701     o0=n0.edAddOutputPort("o0",tsi)
702     n0.setScript("o0=[3,6,8,9,-2,5]")
703     p.edAddChild(n0)
704     n1=self.r.createForEachLoop("n1",ti)
705     n10=self.r.createScriptNode("","n10")
706     n10.setExecutionMode("remote")
707     n10.setContainer(cont)
708     n1.edAddChild(n10)
709     n10.setScript("""
710 import time
711 if i1==9:
712   raise Exception("Simulated error !")
713 else:
714   time.sleep(0.1)
715   o2=2*i1
716 """)
717     i1=n10.edAddInputPort("i1",ti)
718     o2=n10.edAddOutputPort("o2",ti)
719     p.edAddChild(n1)
720     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
721     p.edAddLink(n1.edGetSamplePort(),i1)
722     p.edAddCFLink(n0,n1)
723     n1.edGetNbOfBranchesPort().edInitPy(2)
724     n2=self.r.createScriptNode("","n2")
725     n2.setScript("o4=i3")
726     i3=n2.edAddInputPort("i3",tsi)
727     o4=n2.edAddOutputPort("o4",tsi)
728     n2.setScript("o4=i3")
729     p.edAddChild(n2)
730     p.edAddCFLink(n1,n2)
731     p.edAddLink(o2,i3)
732     p.saveSchema(fname)
733     #
734     l=loader.YACSLoader()
735     p=l.load(fname)
736     n1=p.getChildByName("n1")
737     ex=pilot.ExecutorSwig()
738     ex.setKeepGoingProperty(True)
739     #
740     startt=datetime.now()
741     ex.RunW(p,0)
742     t0=datetime.now()-startt
743     #
744     self.assertEqual(n1.getState(),pilot.FAILED)
745     n1.edGetSeqOfSamplesPort().getPyObj()
746     a,b,c=n1.getPassedResults(ex)
747     self.assertEqual(a,[0,1,2,4,5])
748     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
749     self.assertEqual(c,['n10_o2_interceptor'])
750     
751     p.getChildByName("n1").getChildByName("n10").setScript("""
752 import time
753 if i1==3:
754   time.sleep(2)
755   raise Exception("Simulated error !")
756 else:
757   o2=2*i1
758 """)
759     ex=pilot.ExecutorSwig()
760     ex.setKeepGoingProperty(True)
761     #
762     startt=datetime.now()
763     ex.RunW(p,0)
764     t1=datetime.now()-startt
765     #
766     self.assertEqual(n1.getState(),pilot.FAILED)
767     n1.edGetSeqOfSamplesPort().getPyObj()
768     a,b,c=n1.getPassedResults(ex)
769     self.assertEqual(a,[1,2,3,4,5])
770     self.assertEqual([elt.getPyObj() for elt in b],[[12,16,18,-4,10]])
771     self.assertEqual(c,['n10_o2_interceptor'])
772     pass
773
774   def test9(self):
775     """ Test of assignation of already computed values for foreach node."""
776     fname="test9.xml"
777     from datetime import datetime
778     p=self.r.createProc("prTest2")
779     cont=p.createContainer("gg","Salome")
780     cont.setProperty("name","localhost")
781     cont.setProperty("hostname","localhost")
782     cont.setProperty("type","multi")
783     td=p.createType("double","double")
784     ti=p.createType("int","int")
785     tsi=p.createSequenceTc("seqint","seqint",ti)
786     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
787     n0=self.r.createScriptNode("","n0")
788     o0=n0.edAddOutputPort("o0",tsi)
789     n0.setScript("o0=[3,6,8,9,-2,5]")
790     p.edAddChild(n0)
791     n1=self.r.createForEachLoop("n1",ti)
792     n10=self.r.createScriptNode("","n10")
793     n10.setExecutionMode("remote")
794     n10.setContainer(cont)
795     n1.edAddChild(n10)
796     n10.setScript("""
797 import time
798 if i1==9:
799   raise Exception("Simulated error !")
800 else:
801   time.sleep(0.1)
802   o2=2*i1
803 """)
804     i1=n10.edAddInputPort("i1",ti)
805     o2=n10.edAddOutputPort("o2",ti)
806     p.edAddChild(n1)
807     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
808     p.edAddLink(n1.edGetSamplePort(),i1)
809     p.edAddCFLink(n0,n1)
810     n1.edGetNbOfBranchesPort().edInitPy(2)
811     n2=self.r.createScriptNode("","n2")
812     n2.setScript("o4=i3")
813     i3=n2.edAddInputPort("i3",tsi)
814     o4=n2.edAddOutputPort("o4",tsi)
815     n2.setScript("o4=i3")
816     p.edAddChild(n2)
817     p.edAddCFLink(n1,n2)
818     p.edAddLink(o2,i3)
819     p.saveSchema(fname)
820     #
821     l=loader.YACSLoader()
822     p=l.load(fname)
823     n1=p.getChildByName("n1")
824     ex=pilot.ExecutorSwig()
825     ex.setKeepGoingProperty(True)
826     #
827     startt=datetime.now()
828     ex.RunW(p,0)
829     t0=datetime.now()-startt
830     #
831     self.assertEqual(p.getState(),pilot.FAILED)
832     self.assertEqual(n1.getState(),pilot.FAILED)
833     n1.edGetSeqOfSamplesPort().getPyObj()
834     a,b,c=n1.getPassedResults(ex)
835     self.assertEqual(a,[0,1,2,4,5])
836     self.assertEqual([elt.getPyObj() for elt in b],[[6,12,16,-4,10]])
837     self.assertEqual(c,['n10_o2_interceptor'])
838     
839     p.getChildByName("n1").getChildByName("n10").setScript("""
840 import time
841 time.sleep(2)
842 o2=7*i1
843 """)
844     ex=pilot.ExecutorSwig()
845     ex.setKeepGoingProperty(True)
846     p.getChildByName("n1").assignPassedResults(a,b,c)
847     #
848     startt=datetime.now()
849     ex.RunW(p,0)
850     t1=datetime.now()-startt
851     #
852     self.assertEqual(n1.getState(),pilot.DONE)
853     self.assertEqual(p.getState(),pilot.DONE)
854     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[6,12,16,63,-4,10])
855     pass
856
857   def test10(self):
858     fname="test10.xml"
859     from datetime import datetime
860     p=self.r.createProc("prTest2")
861     cont=p.createContainer("gg","Salome")
862     cont.setProperty("name","localhost")
863     cont.setProperty("hostname","localhost")
864     cont.setProperty("type","multi")
865     td=p.createType("double","double")
866     ti=p.createType("int","int")
867     tsi=p.createSequenceTc("seqint","seqint",ti)
868     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
869     n0=self.r.createScriptNode("","n0")
870     o0=n0.edAddOutputPort("o0",tsi)
871     n0.setScript("o0=[ 3*elt for elt in range(12) ]")
872     p.edAddChild(n0)
873     n1=self.r.createForEachLoop("n1",ti)
874     n10=self.r.createScriptNode("","n10")
875     n10.setExecutionMode("remote")
876     n10.setContainer(cont)
877     n1.edAddChild(n10)
878     n10.setScript("""
879 import time
880 if i1%2==0:
881   raise Exception("Simulated error !")
882 else:
883   time.sleep(0.1)
884   o2=4*i1
885 """)
886     i1=n10.edAddInputPort("i1",ti)
887     o2=n10.edAddOutputPort("o2",ti)
888     p.edAddChild(n1)
889     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
890     p.edAddLink(n1.edGetSamplePort(),i1)
891     p.edAddCFLink(n0,n1)
892     n1.edGetNbOfBranchesPort().edInitPy(2)
893     n2=self.r.createScriptNode("","n2")
894     n2.setScript("o4=i3")
895     i3=n2.edAddInputPort("i3",tsi)
896     o4=n2.edAddOutputPort("o4",tsi)
897     n2.setScript("o4=i3")
898     p.edAddChild(n2)
899     p.edAddCFLink(n1,n2)
900     p.edAddLink(o2,i3)
901     p.saveSchema(fname)
902     #
903     l=loader.YACSLoader()
904     p=l.load(fname)
905     n1=p.getChildByName("n1")
906     ex=pilot.ExecutorSwig()
907     ex.setKeepGoingProperty(True)
908     #
909     startt=datetime.now()
910     ex.RunW(p,0)
911     t0=datetime.now()-startt
912     #
913     self.assertEqual(p.getState(),pilot.FAILED)
914     self.assertEqual(n1.getState(),pilot.FAILED)
915     n1.edGetSeqOfSamplesPort().getPyObj()
916     a,b,c=n1.getPassedResults(ex)
917     self.assertEqual(a,[1,3,5,7,9,11])
918     self.assertEqual([elt.getPyObj() for elt in b],[[12,36,60,84,108,132]])
919     self.assertEqual(c,['n10_o2_interceptor'])
920     
921     p.getChildByName("n1").getChildByName("n10").setScript("""
922 import time
923 if i1%2==1:
924   raise Exception("Simulated error !")
925 else:
926   time.sleep(1)
927   o2=5*i1
928 """)
929     ex=pilot.ExecutorSwig()
930     ex.setKeepGoingProperty(True)
931     p.getChildByName("n1").assignPassedResults(a,b,c)
932     #
933     startt=datetime.now()
934     ex.RunW(p,0)
935     t1=datetime.now()-startt
936     #assert(t1.total_seconds()<6.+1.)# normally 6/2+1 s (6 remaining elts in 2 // branches + 1s to launch container)
937     #
938     self.assertEqual(n1.getState(),pilot.DONE)
939     self.assertEqual(p.getState(),pilot.DONE)
940     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,12,30,36,60,60,90,84,120,108,150,132])
941     pass
942
943   pass
944
945
946   def test11(self):
947     "test if we do not restart from the begining of the schema after an error in a foreach"
948     fname="test11.xml"
949     from datetime import datetime
950     p=self.r.createProc("prTest2")
951     cont=p.createContainer("gg","Salome")
952     cont.setProperty("name","localhost")
953     cont.setProperty("hostname","localhost")
954     cont.setProperty("type","multi")
955     td=p.createType("double","double")
956     ti=p.createType("int","int")
957     tsi=p.createSequenceTc("seqint","seqint",ti)
958     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
959     n0=self.r.createScriptNode("","n0")
960     o0=n0.edAddOutputPort("o0",tsi)
961     n0.setScript("o0=[ elt for elt in range(12) ]")
962     p.edAddChild(n0)
963     n1=self.r.createForEachLoop("n1",ti)
964     n10=self.r.createScriptNode("","n10")
965     n10.setExecutionMode("remote")
966     n10.setContainer(cont)
967     n1.edAddChild(n10)
968     n10.setScript("""
969 import time
970 if i1%2==1:
971   raise Exception("Simulated error !")
972 else:
973   time.sleep(0.1)
974   o2=2*i1
975 """)
976     i1=n10.edAddInputPort("i1",ti)
977     o2=n10.edAddOutputPort("o2",ti)
978     p.edAddChild(n1)
979     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
980     p.edAddLink(n1.edGetSamplePort(),i1)
981     p.edAddCFLink(n0,n1)
982     n1.edGetNbOfBranchesPort().edInitPy(2)
983     n2=self.r.createScriptNode("","n2")
984     n2.setScript("o4=i3")
985     i3=n2.edAddInputPort("i3",tsi)
986     o4=n2.edAddOutputPort("o4",tsi)
987     n2.setScript("o4=i3")
988     p.edAddChild(n2)
989     p.edAddCFLink(n1,n2)
990     p.edAddLink(o2,i3)
991     p.saveSchema(fname)
992     #
993     l=loader.YACSLoader()
994     p=l.load(fname)
995     n1=p.getChildByName("n1")
996     ex=pilot.ExecutorSwig()
997     ex.setKeepGoingProperty(True)
998     #
999     startt=datetime.now()
1000     ex.RunW(p,0)
1001     t0=datetime.now()-startt
1002     #
1003     self.assertEqual(p.getState(),pilot.FAILED)
1004     self.assertEqual(n1.getState(),pilot.FAILED)
1005     n1.edGetSeqOfSamplesPort().getPyObj()
1006     a,b,c=n1.getPassedResults(ex)
1007
1008     self.assertEqual(a,[0,2,4,6,8,10])
1009     self.assertEqual([elt.getPyObj() for elt in b],[[0,4,8,12,16,20]])
1010     
1011     p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(12) ]")
1012     p.getChildByName("n1").getChildByName("n10").setScript("""
1013 import time
1014 if i1%2==0:
1015   raise Exception("Simulated error !")
1016 else:
1017   time.sleep(1)
1018   o2=5*i1
1019 """)
1020     p.resetState(1)
1021
1022
1023     p.getChildByName("n1").assignPassedResults(a,b,c)
1024     p.exUpdateState();
1025     #
1026     startt=datetime.now()
1027     ex.RunW(p,0,False)
1028     t1=datetime.now()-startt
1029     #
1030     self.assertEqual(n1.getState(),pilot.DONE)
1031     self.assertEqual(p.getState(),pilot.DONE)
1032     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,5,4,15,8,25,12,35,16,45,20,55])
1033     pass
1034   
1035   def test12(self):
1036     """ Test of nested ForEachLoop with a port connected inside and outside the loop."""
1037     schema = self.r.createProc("schema")
1038     ti = schema.getTypeCode("int")
1039     tiset = schema.createSequenceTc("", "seqint", ti)
1040     tisetseq = schema.createSequenceTc("", "seqintvec", tiset)
1041
1042     n1 = self.r.createScriptNode("", "PyScript2")
1043     n1.edAddInputPort("i3", ti)
1044     n1.edAddInputPort("i4", ti)
1045     n1.edAddOutputPort("o5", ti)
1046     n1.setScript("o5=i3+i4")
1047
1048     n2 = self.r.createScriptNode("", "PyScript1")
1049     n2.edAddInputPort("i2", ti)
1050     n2.edAddOutputPort("o3", ti)
1051     n2.setScript("o3=i2")
1052
1053     b1 = self.r.createBloc("Bloc1")
1054     b1.edAddChild(n1)
1055     b1.edAddChild(n2)
1056
1057     fe1 = self.r.createForEachLoop("ForEach1", ti)
1058     fe1.getInputPort("nbBranches").edInitPy(2)
1059     fe1.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
1060     fe1.edSetNode(b1)
1061
1062     n3 = self.r.createScriptNode("", "PostProcessing")
1063     n3.edAddInputPort("i7", tiset)
1064     n3.edAddInputPort("i5", tiset)
1065     n3.edAddOutputPort("o4", ti)
1066     n3.setScript("""
1067 o4 = 0
1068 for i in i7:
1069     o4 = i + o4
1070
1071 for i in i5:
1072     o4 = i + o4
1073 """)
1074
1075     b0 = self.r.createBloc("Bloc0")
1076     b0.edAddChild(fe1)
1077     b0.edAddChild(n3)
1078
1079     fe0 = self.r.createForEachLoop("ForEach1", ti)
1080     fe0.getInputPort("nbBranches").edInitPy(2)
1081     fe0.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
1082     fe0.edSetNode(b0)
1083
1084     schema.edAddChild(fe0)
1085
1086     nx = self.r.createScriptNode("", "Result")
1087     nx.edAddInputPort("i8", tiset)
1088     nx.edAddOutputPort("o6", ti)
1089     nx.setScript("""
1090 o6 = 0
1091 for i in i8:
1092     o6 = i + o6
1093 """)
1094     schema.edAddChild(nx)
1095
1096     schema.edAddLink(fe1.getOutputPort("evalSamples"), n1.getInputPort("i3"))
1097     schema.edAddLink(fe0.getOutputPort("evalSamples"), n1.getInputPort("i4"))
1098
1099     schema.edAddDFLink(n1.getOutputPort("o5"), n3.getInputPort("i7"))
1100     schema.edAddDFLink(n2.getOutputPort("o3"), n3.getInputPort("i5"))
1101
1102     po5 = fe1.getOutputPort("Bloc1.PyScript2.o5")
1103     schema.edAddDFLink(po5, n2.getInputPort("i2"))
1104
1105     schema.edAddDFLink(n3.getOutputPort("o4"), nx.getInputPort("i8"))
1106 #    schema.saveSchema("foreach12.xml")
1107     
1108     e = pilot.ExecutorSwig()
1109     e.RunW(schema)
1110     self.assertEqual(schema.getState(),pilot.DONE)
1111     resVal = schema.getChildByName("Result").getOutputPort("o6").getPyObj()
1112     self.assertEqual(resVal, 160)
1113     pass
1114
1115   def test13(self):
1116     """ Non regression test EDF11239. ForEach into ForEach. Problem on cloning linked to DeloymentTree.appendTask method that was too strong."""
1117     p=self.r.createProc("Bug11239")
1118     ti=p.createType("int","int")
1119     ti2=p.createSequenceTc("seqint","seqint",ti)
1120     #
1121     cont=p.createContainer("DefaultContainer","Salome")
1122     #
1123     node0=self.r.createForEachLoop("ForEachLoop_int0",ti)
1124     p.edAddChild(node0)
1125     node0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
1126     node0.edGetNbOfBranchesPort().edInitInt(2)
1127     #
1128     node00=self.r.createBloc("Bloc0")
1129     node0.edAddChild(node00)
1130     node000_0=self.r.createForEachLoop("ForEachLoop_int1",ti)
1131     node00.edAddChild(node000_0)
1132     node000_0.edGetSeqOfSamplesPort().edInitPy(list(range(4)))
1133     node000_0.edGetNbOfBranchesPort().edInitInt(3)
1134     #
1135     node0000=self.r.createBloc("Bloc1")
1136     node000_0.edAddChild(node0000)
1137     #
1138     node0000_0=self.r.createScriptNode("","PyScript2")
1139     node0000.edAddChild(node0000_0)
1140     i3=node0000_0.edAddInputPort("i3",ti)
1141     i4=node0000_0.edAddInputPort("i4",ti)
1142     o5=node0000_0.edAddOutputPort("o5",ti)
1143     node0000_0.setScript("o5 = i3 + i4")
1144     node0000_0.setContainer(cont)
1145     node0000_0.setExecutionMode("remote")
1146     p.edAddLink(node0.edGetSamplePort(),i3)
1147     p.edAddLink(node000_0.edGetSamplePort(),i4)
1148     #
1149     node0000_1=self.r.createScriptNode("","PyScript1")
1150     node0000.edAddChild(node0000_1)
1151     o3=node0000_1.edAddOutputPort("o3",ti)
1152     node0000_1.setScript("o3 = 7")
1153     node0000_1.setExecutionMode("local")
1154     p.edAddCFLink(node0000_0,node0000_1)
1155     #
1156     node000_1=self.r.createScriptNode("","PostTraitement")
1157     node00.edAddChild(node000_1)
1158     i7=node000_1.edAddInputPort("i7",ti2)
1159     i5=node000_1.edAddInputPort("i5",ti2)
1160     node000_1.setScript("for i in i7:\n    print(i)\nprint(\"separation\")\nfor i in i5:\n    print(i)")
1161     node000_1.setContainer(cont)
1162     node000_1.setExecutionMode("remote")
1163     p.edAddLink(o5,i7)
1164     p.edAddLink(o3,i5)
1165     p.edAddCFLink(node000_0,node000_1)
1166     #
1167     #p.saveSchema("tmpp.xml")
1168     ex = pilot.ExecutorSwig()
1169     self.assertEqual(p.getState(),pilot.READY)
1170     ex.RunW(p,0)
1171     self.assertEqual(p.getState(),pilot.DONE)
1172     pass
1173
1174   def test14(self):
1175     """ Non regression EDF11027. Problem after Save/Load of a foreach node with type pyobj with input "SmplsCollection" manually set before. Correction in convertToYacsObjref from XML->Neutral. Objref can hide a string !"""
1176     xmlFileName="test14.xml"
1177     SALOMERuntime.RuntimeSALOME_setRuntime()
1178     r=pilot.getRuntime()
1179     n0=r.createProc("test23/zeRun")
1180     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1181     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
1182     n0bis=r.createBloc("test23/main") ; n0.edAddChild(n0bis)
1183     n00=r.createBloc("test23/run") ; n0bis.edAddChild(n00)
1184     #
1185     n000=r.createForEachLoop("test23/FE",tp) ; n00.edAddChild(n000)
1186     n0000=r.createScriptNode("Salome","test23/run_internal") ; n000.edSetNode(n0000)
1187     i0=n0000.edAddInputPort("i0",tp)
1188     i1=n0000.edAddInputPort("i1",tp) ; i1.edInitPy(3)
1189     o0=n0000.edAddOutputPort("o0",tp)
1190     n0000.setScript("o0=i0+i1")
1191     #
1192     n00.edAddLink(n000.edGetSamplePort(),i0)
1193     #
1194     n000.edGetSeqOfSamplesPort().edInitPy(list(range(10)))
1195     n000.edGetNbOfBranchesPort().edInitInt(2)
1196     #
1197     n01=r.createScriptNode("Salome","test23/check") ; n0bis.edAddChild(n01)
1198     n0bis.edAddCFLink(n00,n01)
1199     i2=n01.edAddInputPort("i2",tp2)
1200     o1=n01.edAddOutputPort("o1",tp2)
1201     n01.setScript("o1=i2")
1202     n0bis.edAddLink(o0,i2)
1203     #
1204     n0.saveSchema(xmlFileName)
1205     #
1206     l=loader.YACSLoader()
1207     p=l.load(xmlFileName) # very import do not use n0 but use p instead !
1208     ex=pilot.ExecutorSwig()
1209     #
1210     self.assertEqual(p.getState(),pilot.READY)
1211     ex.RunW(p,0)
1212     self.assertEqual(p.getState(),pilot.DONE)
1213     self.assertEqual(p.getChildByName("test23/main.test23/check").getOutputPort("o1").getPyObj(),[3,4,5,6,7,8,9,10,11,12])
1214     pass
1215
1216   def test15(self):
1217     fname="BugInConcurrentLaunchDftCont.xml"
1218     p=self.r.createProc("pr")
1219     ti=p.createType("int","int")
1220     cont=p.createContainer("DefaultContainer","Salome")
1221     cont.setProperty("container_name","FactoryServer")
1222     b=self.r.createBloc("Bloc") ; p.edAddChild(b)
1223     #
1224     nb=4
1225     outs=[]
1226     for i in range(nb):
1227       node=self.r.createScriptNode("Salome","node%d"%i)
1228       node.setExecutionMode("remote")
1229       node.setContainer(cont)
1230       outs.append(node.edAddOutputPort("i",ti))
1231       node.setScript("i=%d"%i)
1232       b.edAddChild(node)
1233     #
1234     node=self.r.createScriptNode("Salome","nodeEnd")
1235     node.setExecutionMode("remote")
1236     node.setContainer(cont)
1237     res=node.edAddOutputPort("res",ti)
1238     p.edAddChild(node)
1239     l=[]
1240     for i in range(nb):
1241       elt="i%d"%i
1242       inp=node.edAddInputPort(elt,ti) ; l.append(elt)
1243       p.edAddChild(node)
1244       p.edAddLink(outs[i],inp)
1245     node.setScript("res="+"+".join(l))
1246     p.edAddCFLink(b,node)
1247     #
1248     for i in range(10):
1249       p.init()
1250       ex = pilot.ExecutorSwig()
1251       self.assertEqual(p.getState(),pilot.READY)
1252       ex.RunW(p,0)
1253       self.assertEqual(res.getPyObj(),6)
1254       self.assertEqual(p.getState(),pilot.DONE)
1255     pass
1256
1257   def test16(self):
1258     """ Test to check that a list[pyobj] outputport linked to pyobj inputport is OK."""
1259     SALOMERuntime.RuntimeSALOME_setRuntime()
1260     self.r=pilot.getRuntime()
1261     n0=self.r.createProc("test16/zeRun")
1262     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1263     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tp)
1264     
1265     n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
1266     o0=n00.edAddOutputPort("o0",tp2)
1267     n00.setScript("o0=[[i+1] for i in range(8)]")
1268     n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
1269     i1=n01.edAddInputPort("i1",tp)
1270     n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
1271     n0.edAddCFLink(n00,n01)
1272     n0.edAddLink(o0,i1)
1273     #
1274     ex=pilot.ExecutorSwig()
1275     self.assertEqual(n0.getState(),pilot.READY)
1276     ex.RunW(n0,0)
1277     self.assertEqual(n0.getState(),pilot.DONE)
1278     pass
1279
1280   def test17(self):
1281     """ Same as test16 except that tp2 is not list of tp but a list of copy of tp"""
1282     SALOMERuntime.RuntimeSALOME_setRuntime()
1283     self.r=pilot.getRuntime()
1284     n0=self.r.createProc("test17/zeRun")
1285     tp=n0.createInterfaceTc("python:obj:1.0","pyobj",[])
1286     tpp=n0.createInterfaceTc("python:obj:1.0","pyobj",[]) # diff is here
1287     tp2=n0.createSequenceTc("list[pyobj]","list[pyobj]",tpp)
1288     
1289     n00=self.r.createScriptNode("Salome","n00") ; n0.edAddChild(n00)
1290     o0=n00.edAddOutputPort("o0",tp2)
1291     n00.setScript("o0=[[i+1] for i in range(8)]")
1292     n01=self.r.createScriptNode("Salome","n01") ; n0.edAddChild(n01)
1293     i1=n01.edAddInputPort("i1",tp)
1294     n01.setScript("assert(i1==[[1], [2], [3], [4], [5], [6], [7], [8]])")
1295     n0.edAddCFLink(n00,n01)
1296     n0.edAddLink(o0,i1)
1297     #
1298     ex=pilot.ExecutorSwig()
1299     self.assertEqual(n0.getState(),pilot.READY)
1300     ex.RunW(n0,0)
1301     self.assertEqual(n0.getState(),pilot.DONE)
1302     pass
1303
1304   def test18(self):
1305     p=self.r.createProc("prTest18")
1306     n00=self.r.createScriptNode("Salome","n00")
1307     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1308     n00.setExecutionMode("remote")
1309     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1310     cont=p.createContainer("gg","Salome")
1311     n00.setContainer(cont)
1312     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1313     cont.setProperty("nb_proc_per_nod","6")
1314     self.assertEqual(n00.getMaxLevelOfParallelism(),1)
1315     cont.setProperty("nb_proc_per_node","7")           # <- here
1316     self.assertEqual(n00.getMaxLevelOfParallelism(),7) # <- here
1317     pass
1318     
1319   def test19(self):
1320     """This test checks the mechanism of YACS that allow PythonNodes to know their DynParaLoop context."""
1321     fname="test19.xml"
1322     l=loader.YACSLoader()
1323     #
1324     p=self.r.createProc("PROC")
1325     ti=p.createType("int","int")
1326     tdi=p.createSequenceTc("seqint","seqint",ti)
1327     # Level0
1328     fe0=self.r.createForEachLoop("FE0",ti) ; p.edAddChild(fe0)
1329     fe0.edGetNbOfBranchesPort().edInitInt(4)
1330     fe0_end=self.r.createScriptNode("Salome","fe0_end")
1331     fe0.edSetFinalizeNode(fe0_end)
1332     fe0_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
1333 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)""")
1334     n0=self.r.createScriptNode("Salome","n0") ; p.edAddChild(n0)
1335     n0.setScript("o1=range(10)")
1336     a=n0.edAddOutputPort("o1",tdi)
1337     p.edAddLink(a,fe0.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n0,fe0)
1338     # Level1
1339     b0=self.r.createBloc("b0") ; fe0.edAddChild(b0)
1340     n1=self.r.createScriptNode("Salome","n1") ; b0.edAddChild(n1)
1341     n1.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0"])
1342 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<4)
1343 o1=range(10)""")
1344     b=n1.edAddOutputPort("o1",tdi)
1345     fe1=self.r.createForEachLoop("FE1",ti) ; b0.edAddChild(fe1)
1346     fe1.edGetNbOfBranchesPort().edInitInt(3)
1347     fe1_end=self.r.createScriptNode("Salome","fe1_end")
1348     fe1_end.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
1349 assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
1350 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
1351 """)
1352     fe1.edSetFinalizeNode(fe1_end)
1353     p.edAddLink(b,fe1.edGetSeqOfSamplesPort()) ; p.edAddCFLink(n1,fe1)
1354     # Level2
1355     n2=self.r.createScriptNode("Salome","n2") ; fe1.edAddChild(n2)
1356     n2.setScript("""assert([elt[0] for elt in my_dpl_localization]==["FE0.b0.FE1","FE0"])
1357 assert(my_dpl_localization[1][1]>=0 and my_dpl_localization[1][1]<4)
1358 assert(my_dpl_localization[0][1]>=0 and my_dpl_localization[0][1]<3)
1359 """)
1360     
1361     p.saveSchema(fname)
1362     ex=pilot.ExecutorSwig()
1363     
1364     # local run of PythonNodes n1 and n2
1365     p=l.load(fname)
1366     p.init()
1367     self.assertEqual(p.getState(),pilot.READY)
1368     ex.setDPLScopeSensitive(True) # <- this line is the aim of the test
1369     ex.RunW(p,0)
1370     self.assertEqual(p.getState(),pilot.DONE)
1371
1372     # run remote
1373     p=l.load(fname)
1374     cont=p.createContainer("gg","HPSalome")
1375     cont.setSizeOfPool(2)
1376     n1=p.getChildByName("FE0.b0.n1") ; n1.setExecutionMode("remote") ; n1.setContainer(cont)
1377     n2=p.getChildByName("FE0.b0.FE1.n2") ; n2.setExecutionMode("remote") ; n2.setContainer(cont)
1378     
1379     p.init()
1380     self.assertEqual(p.getState(),pilot.READY)
1381     ex.RunW(p,0)
1382     self.assertEqual(p.getState(),pilot.DONE)
1383     pass
1384
1385   def test20(self):
1386     """This test revealed a huge bug in ElementaryNode contained in a loop or foreach. The RECONNECT state generated invalid dependancies that only HPContainer can reveal the problem"""
1387     def assignCont(n,cont):
1388       n.setExecutionMode("remote") ; n.setContainer(cont) 
1389       pass
1390     xmlFileName="test20.xml"
1391     p=self.r.createProc("test26")
1392     #
1393     cont=p.createContainer("gg","HPSalome") # very important ! HP Container needed for the test !
1394     cont.setSizeOfPool(8) # important make this figure >= 6
1395     #
1396     po=p.createInterfaceTc("python:obj:1.0","pyobj",[])
1397     sop=p.createSequenceTc("list[pyobj]","list[pyobj]",po)
1398     #
1399     b0=self.r.createBloc("test26/main") ; p.edAddChild(b0)
1400     n0=self.r.createScriptNode("Salome","test26/n0") ; assignCont(n0,cont) # 1
1401     n0.setScript("""import os
1402 dd=range(10)""")
1403     dd=n0.edAddOutputPort("dd",sop) ; b0.edAddChild(n0)
1404     fe0=self.r.createForEachLoop("test26/FE0",po) ; b0.edAddChild(fe0)
1405     fe0.edGetNbOfBranchesPort().edInitInt(1) # very important for the test : 1 !
1406     fe0i=self.r.createBloc("test26/FE0_internal") ; fe0.edSetNode(fe0i)
1407     zeArgInitNode2=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode2,cont) # 2
1408     fe0i.edAddChild(zeArgInitNode2)
1409     c1=zeArgInitNode2.edAddInputPort("c",po)
1410     c2=zeArgInitNode2.edAddOutputPort("c",po)
1411     zeRun=self.r.createBloc("test26/zeRun") ; fe0i.edAddChild(zeRun)
1412     zeArgInitNode=self.r.createScriptNode("Salome","zeArgInitNode") ; assignCont(zeArgInitNode,cont) # 3
1413     zeRun.edAddChild(zeArgInitNode)
1414     ff1=zeArgInitNode.edAddInputPort("ff",po)
1415     ff2=zeArgInitNode.edAddOutputPort("ff",po)
1416     line01=self.r.createScriptNode("Salome","line01") ; zeRun.edAddChild(line01) ; assignCont(line01,cont) # 4
1417     line01.setScript("ee=3")
1418     ee0=line01.edAddOutputPort("ee",po)
1419     initt=self.r.createScriptNode("Salome","test26/initt") ; assignCont(initt,cont) # 5
1420     initt.setScript("pass") ; zeRun.edAddChild(initt)
1421     end=self.r.createScriptNode("Salome","test26/end") ; assignCont(end,cont) # 6
1422     end.setScript("import os") ; zeRun.edAddChild(end)
1423     retu=self.r.createScriptNode("Salome","return") ; assignCont(retu,cont) # 7
1424     retu.setScript("ee=i0") ; zeRun.edAddChild(retu)
1425     i0=retu.edAddInputPort("i0",po)
1426     ee=retu.edAddOutputPort("ee",po)
1427     zeRun.edAddCFLink(zeArgInitNode,line01)
1428     zeRun.edAddCFLink(line01,initt)
1429     zeRun.edAddCFLink(initt,end)
1430     zeRun.edAddCFLink(end,retu)
1431     p.edAddLink(ee0,i0)
1432     #
1433     returnn=self.r.createScriptNode("Salome","return") ; assignCont(returnn,cont) # 8
1434     returnn.setScript("elt=i0")
1435     i00=returnn.edAddInputPort("i0",po)
1436     elt=returnn.edAddOutputPort("elt",po)
1437     fe0i.edAddChild(returnn)
1438     fe0i.edAddCFLink(zeArgInitNode2,zeRun)
1439     fe0i.edAddCFLink(zeRun,returnn)
1440     p.edAddLink(c2,ff1)
1441     p.edAddLink(ee,i00)
1442     #
1443     finalize=self.r.createScriptNode("Salome","test26/finalize") ; b0.edAddChild(finalize) ; assignCont(finalize,cont) # 9
1444     finalize.setScript("pass")
1445     b0.edAddCFLink(n0,fe0)
1446     b0.edAddCFLink(fe0,finalize)
1447     #
1448     p.edAddLink(dd,fe0.edGetSeqOfSamplesPort())
1449     p.edAddLink(fe0.edGetSamplePort(),c1)
1450     #
1451     #p.saveSchema(xmlFileName)
1452     p.getChildByName("test26/main.test26/FE0").edGetNbOfBranchesPort().edInitInt(1) # very important 1 !
1453     #
1454     ex=pilot.ExecutorSwig()
1455     self.assertEqual(p.getState(),pilot.READY)
1456     ex.RunW(p,0)
1457     self.assertEqual(p.getState(),pilot.DONE)
1458     pass
1459
1460   pass
1461
1462   def test21(self):
1463     "test if we restart from a saved state in a foreach loop"
1464     fname="test21.xml"
1465     xmlStateFileName="saveState21.xml"
1466     from datetime import datetime
1467     p=self.r.createProc("prTest21")
1468     cont=p.createContainer("gg","Salome")
1469     cont.setProperty("name","localhost")
1470     cont.setProperty("hostname","localhost")
1471     cont.setProperty("type","multi")
1472     td=p.createType("double","double")
1473     ti=p.createType("int","int")
1474     tsi=p.createSequenceTc("seqint","seqint",ti)
1475     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
1476     n0=self.r.createScriptNode("","n0")
1477     o0=n0.edAddOutputPort("o0",tsi)
1478     n0.setScript("o0=[ elt for elt in range(6) ]")
1479     p.edAddChild(n0)
1480     n1=self.r.createForEachLoop("n1",ti)
1481     n10=self.r.createScriptNode("","n10")
1482     n10.setExecutionMode("remote")
1483     n10.setContainer(cont)
1484     n1.edAddChild(n10)
1485     n10.setScript("""
1486 import time
1487 time.sleep(2)
1488 o2=2*i1
1489 """)
1490     i1=n10.edAddInputPort("i1",ti)
1491     o2=n10.edAddOutputPort("o2",ti)
1492     p.edAddChild(n1)
1493     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
1494     p.edAddLink(n1.edGetSamplePort(),i1)
1495     p.edAddCFLink(n0,n1)
1496     n1.edGetNbOfBranchesPort().edInitPy(2)
1497     n2=self.r.createScriptNode("","n2")
1498     n2.setScript("o4=i3")
1499     i3=n2.edAddInputPort("i3",tsi)
1500     o4=n2.edAddOutputPort("o4",tsi)
1501     n2.setScript("o4=i3")
1502     p.edAddChild(n2)
1503     p.edAddCFLink(n1,n2)
1504     p.edAddLink(o2,i3)
1505     p.saveSchema(fname)
1506     #
1507     l=loader.YACSLoader()
1508     p=l.load(fname)
1509     n1=p.getChildByName("n1")
1510     ex=pilot.ExecutorSwig()
1511     ex.setKeepGoingProperty(True)
1512     #
1513     startt=datetime.now()
1514     import threading
1515     myRun=threading.Thread(None, ex.RunW, None, (p,0))
1516     myRun.start()
1517     import time
1518     time.sleep(5)
1519     SALOMERuntime.schemaSaveState(p, ex, xmlStateFileName)
1520     a,b,c=n1.getPassedResults(ex)
1521     myRun.join()
1522     t0=datetime.now()-startt
1523     #
1524     self.assertEqual(p.getState(),pilot.DONE)
1525     self.assertEqual(n1.getState(),pilot.DONE)
1526     self.assertEqual(a,[0,1])
1527     self.assertEqual([elt.getPyObj() for elt in b],[[0,2]])
1528     #
1529     p.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
1530     p.getChildByName("n1").getChildByName("n10").setScript("""
1531 import time
1532 time.sleep(0.1)
1533 o2=5*i1
1534 """)
1535     loader.loadState(p, xmlStateFileName)
1536     p.resetState(1)
1537     p.getChildByName("n1").assignPassedResults(a,b,c)
1538     p.exUpdateState();
1539     #
1540     startt=datetime.now()
1541     ex.RunW(p,0,False)
1542     t1=datetime.now()-startt
1543     #
1544     self.assertEqual(n1.getState(),pilot.DONE)
1545     self.assertEqual(p.getState(),pilot.DONE)
1546     self.assertEqual(p.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
1547     pass
1548   pass
1549
1550   def test22(self):
1551     """Restart from a saved state in a foreach loop without using assignPassedResults.
1552        This test uses the files test21.xml and saveState21.xml produced by test21.
1553     """
1554     fname="test21.xml"
1555     xmlStateFileName="saveState21.xml"
1556
1557     ex=pilot.ExecutorSwig()
1558     l=loader.YACSLoader()
1559     q=l.load(fname)
1560     q.getChildByName("n0").setScript("o0=[ 3*elt for elt in range(6) ]")
1561     q.getChildByName("n1").getChildByName("n10").setScript("""
1562 import time
1563 time.sleep(0.1)
1564 print("execution n10:", i1)
1565 o2=5*i1
1566 """)
1567     q.getChildByName("n2").setScript("""
1568 print("execution n2:", i3)
1569 o4=i3
1570 """)
1571     loader.loadState(q, xmlStateFileName)
1572     q.resetState(1)
1573     q.exUpdateState()
1574     #
1575     ex.RunW(q,0,False)
1576     #
1577     self.assertEqual(q.getChildByName("n1").getState(),pilot.DONE)
1578     self.assertEqual(q.getState(),pilot.DONE)
1579     self.assertEqual(q.getChildByName("n2").getOutputPort("o4").getPyObj(),[0,2,10,15,20,25])
1580     pass
1581
1582   def test23(self):
1583     """ test focused on weight attribut after a dump and reload from a xml file
1584     """
1585     fname="test23.xml"
1586     xmlStateFileName="saveState23.xml"
1587     from datetime import datetime
1588     p=self.r.createProc("prTest23")
1589     cont=p.createContainer("gg","Salome")
1590     cont.setProperty("name","localhost")
1591     cont.setProperty("hostname","localhost")
1592     cont.setProperty("type","multi")
1593     td=p.createType("double","double")
1594     ti=p.createType("int","int")
1595     tsi=p.createSequenceTc("seqint","seqint",ti)
1596     tsd=p.createSequenceTc("seqdbl","seqdbl",td)
1597     n0=self.r.createScriptNode("","n0")
1598     o0=n0.edAddOutputPort("o0",tsi)
1599     n0.setScript("o0=[ elt for elt in range(6) ]")
1600     p.edAddChild(n0)
1601     n1=self.r.createForEachLoop("n1",ti)
1602     n1.setWeight(3)
1603     n10=self.r.createScriptNode("","n10")
1604     n10.setExecutionMode("remote")
1605     n10.setContainer(cont)
1606     n1.edAddChild(n10)
1607     n10.setScript("""
1608 import time
1609 time.sleep(2)
1610 o2=2*i1
1611 """)
1612     n10.setWeight(4.)
1613     i1=n10.edAddInputPort("i1",ti)
1614     o2=n10.edAddOutputPort("o2",ti)
1615     p.edAddChild(n1)
1616     p.edAddLink(o0,n1.edGetSeqOfSamplesPort())
1617     p.edAddLink(n1.edGetSamplePort(),i1)
1618     p.edAddCFLink(n0,n1)
1619     n1.edGetNbOfBranchesPort().edInitPy(2)
1620     n2=self.r.createScriptNode("","n2")
1621     n2.setScript("o4=i3")
1622     i3=n2.edAddInputPort("i3",tsi)
1623     o4=n2.edAddOutputPort("o4",tsi)
1624     n2.setScript("o4=i3")
1625     p.edAddChild(n2)
1626     p.edAddCFLink(n1,n2)
1627     p.edAddLink(o2,i3)
1628     p.saveSchema(fname)
1629     #
1630     l=loader.YACSLoader()
1631     p=l.load(fname)
1632     self.assertEqual(p.getChildByName("n1").getWeight().getSimpleLoopWeight(),3.0)
1633     self.assertEqual(p.getChildByName("n1").getChildByName("n10").getWeight().getElementaryWeight(),4.0)
1634     pass
1635
1636   def test24(self):
1637     """ Non regression test EDF17470"""
1638     SALOMERuntime.RuntimeSALOME.setRuntime()
1639     r=SALOMERuntime.getSALOMERuntime()
1640     p=r.createProc("prTest2")
1641     #
1642     cont1=p.createContainer("cont1","Salome")
1643     cont1.setProperty("name","localhost")
1644     cont1.setProperty("hostname","localhost")
1645     cont1.setProperty("type","multi")
1646     cont1.setProperty("container_name","container1@")
1647     #
1648     cont2=p.createContainer("cont2","Salome")
1649     cont2.setProperty("name","localhost")
1650     cont2.setProperty("hostname","localhost")
1651     cont2.setProperty("type","multi")
1652     cont2.setProperty("container_name","container2@")
1653     #
1654     td=p.createType("double","double")
1655     ti=p.createType("int","int")
1656     ts=p.createType("string","string")
1657     n0=r.createScriptNode("","n0")
1658     n0.setScript("""import SalomeSDSClt
1659 import SALOME
1660 import salome
1661 import unittest
1662 import pickle
1663 import gc
1664 import time
1665
1666 def obj2Str(obj):
1667   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1668 def str2Obj(strr):
1669   return pickle.loads(strr)
1670
1671
1672 salome.salome_init()
1673 scopeName="Scope1"
1674 varName="a"
1675 dsm=salome.naming_service.Resolve("/DataServerManager")
1676 dsm.cleanScopesInNS()
1677 if scopeName in dsm.listScopes():
1678   dsm.removeDataScope(scopeName)
1679 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1680 #
1681 t0=dss.createRdExtVarTransac(varName,obj2Str({"ab":[4,5,6]}))
1682 dss.atomicApply([t0])
1683 """)
1684     n0_sn=n0.edAddOutputPort("scopeName",ts)
1685     n0_vn=n0.edAddOutputPort("varName",ts)
1686     #
1687     n1=r.createScriptNode("","n1")
1688     n1_sn=n1.edAddInputPort("scopeName",ts)
1689     n1_vn=n1.edAddInputPort("varName",ts)
1690     n1.setScript("""import SalomeSDSClt
1691 import SALOME
1692 import salome
1693 import unittest
1694 import pickle
1695 import gc
1696 import time
1697
1698
1699 def obj2Str(obj):
1700   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1701 def str2Obj(strr):
1702   return pickle.loads(strr)
1703
1704 salome.salome_init()
1705 dsm=salome.naming_service.Resolve("/DataServerManager")
1706 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1707 assert(not isCreated)
1708
1709 t1=dss.addMultiKeyValueSession(varName)
1710 # lecture 'ef'
1711 wk2=dss.waitForKeyInVar(varName,obj2Str("ef"))
1712 wk2.waitFor()
1713 assert(str2Obj(dss.waitForMonoThrRev(wk2))==[11,12])""")
1714     n1.setContainer(cont1)
1715     #
1716     n2=r.createScriptNode("","n2")
1717     n2_sn=n2.edAddInputPort("scopeName",ts)
1718     n2_vn=n2.edAddInputPort("varName",ts)
1719     n2.setScript("""import SalomeSDSClt
1720 import SALOME
1721 import salome
1722 import unittest
1723 import pickle
1724 import gc
1725 import time
1726
1727
1728 def obj2Str(obj):
1729   return pickle.dumps(obj,pickle.HIGHEST_PROTOCOL)
1730 def str2Obj(strr):
1731   return pickle.loads(strr)
1732
1733 salome.salome_init()
1734 dsm=salome.naming_service.Resolve("/DataServerManager")
1735 dss,isCreated=dsm.giveADataScopeTransactionCalled(scopeName)
1736 assert(not isCreated)
1737 time.sleep(3.)
1738 t1=dss.addMultiKeyValueSession(varName)
1739 t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("cd"),obj2Str([7,8,9,10]))
1740 t1.addKeyValueInVarErrorIfAlreadyExistingNow(obj2Str("ef"),obj2Str([11,12]))
1741 """)
1742     n2.setContainer(cont2)
1743     #
1744     p.edAddChild(n0)
1745     p.edAddChild(n1)
1746     p.edAddChild(n2)
1747     p.edAddCFLink(n0,n1)
1748     p.edAddCFLink(n0,n2)
1749     p.edAddLink(n0_sn,n1_sn)
1750     p.edAddLink(n0_vn,n1_vn)
1751     p.edAddLink(n0_sn,n2_sn)
1752     p.edAddLink(n0_vn,n2_vn)
1753     #
1754     ex=pilot.ExecutorSwig()
1755     ex.RunW(p,0)
1756     self.assertEqual(p.getState(),pilot.DONE)
1757     pass
1758
1759   def test25(self):
1760     fname="test25.xml"
1761     p=self.r.createProc("p0")
1762     tp=p.createInterfaceTc("python:obj:1.0","pyobj",[])
1763     n1_0_sc=self.r.createScriptNode("Salome","n1_0_sc")
1764     p.edAddChild(n1_0_sc)
1765     n1_0_sc.setExecutionMode("remote")
1766     n1_0_sc.setScript("""""")
1767     i1_0_sc=n1_0_sc.edAddInputPort("i1",tp)
1768     i1_0_sc.edInitPy(list(range(4)))
1769
1770     cont=p.createContainer("gg","Salome")
1771     cont.setProperty("name","localhost")
1772     cont.setProperty("hostname","localhost")
1773     n1_0_sc.setContainer(cont)
1774
1775     p.saveSchema(fname)
1776     l=loader.YACSLoader()
1777     p=l.load(fname)
1778     ex=pilot.ExecutorSwig()
1779     self.assertEqual(p.getState(),pilot.READY)
1780     ex.RunW(p,0)
1781     self.assertEqual(p.getState(),pilot.DONE)
1782     pass
1783
1784   def test27(self):
1785     """ 
1786     This test is here to check that old (<=930) graphs are always loadable.
1787     So an xml file coming from test14 in 930 has been generated and converted into home made "base64" like format.
1788     This test puts unbased64 byte array into test_930.xml and load it to check that everything is OK.
1789     """
1790     import os
1791     content_of_file = b'DDkShXM2PeNCndPqRfnYX5EAt.GaRgPq7dNqtfnYZgvqh=kQf7moXCE2z5lED.tCxgM2RcOqdfl29ePC9YnAx3uaGetqF5lE=.E2D0uS1eM2RcOqdfl2FjPqBYE2pdNq7fl2FjPqBYHoT3.2=.Ew9dsCdUFqVfOaj2Eaxet4BeN2=BOKRWOwF0PqfYMqdYHoT3.2=.EwxYNKHeNa=5O4heOwF4OKBeN2=7Maj2FaZXOaFDFwI.E2=1kibUua=5O4heOwF7Nq9YE2pdNq7fl2ZbMiFDFwI.E2=1nqFZNCdaM2RcOqdfl21dvqFZN2=7Maj2ECbWsKxbNQxYNKL6lo12HoT3.2=.EwneOCfeNqleM2RcOqdfl2BdPC9hcCbjN4Jfd2=APqRWuaRWuwF.uSxYNKFDFwI.E2=1kibUua=5O4heOwFAsiHdNqtYE2pdNq7fl2nWtCZbPaFDFwI.E2=1n4xbMiVdNqdYs2RcOqdfl26eNaVesq9g9qRWu4ZbOaHYFwI.E2=.E2=1kCHjMCdYsibUFqVfOaj2H4xbMiVdNqdYvupdNq7YE2PcMqfeOwFAe4BjOqdYHoT3.2=.E2=.Ew1Yvq1eNC9ds2RcOqdfl2VWsiVgMKdWPuxbPulXPqRdNqtYE2PcMqfeOwF.l2x5lE=.E2=.E2D.tCxUuaHWuS=5O4heOwFAPqRWu4ZbOaHjdqVfOaF.FiVXOidfl2McP49jNCbgeaHauaHYHoT3.2=.E2=.Ew1Yvq1eNC9ds2RcOqdfl2RcOqdYE2PcMqfeOwF1PqlcMq3jPC9YHoT3.2=.EwxAPqRWu4ZbOaHblE=.E2D2MqxgM2RcOqdfl29ePC9YnAx9O4ZbN2T3.2=.E2=.EwFXPqlUFqVfOaj2EidgsiHAnoHetqF5lE=.E2=.E2=.E2D4PqHeO4lVM2RcOqdfl29ePC9YnAx48WF.FqFYu4RgMKj2FAF.EqxjMCueOKtVMij2GoX2E29dsCdfl21dvqFZN2T3.2=.E2=.E2=.E2=.EwZbMqZbOa=5O4heOwF0uanWtAnDFCfbPuZbMidYtqVXN2T3.2=.E2=.E2=.E2=.E2=.EwngNCZUsiT1n4xWOaT1m2qg6WUWe0qjMAj7MAp7OAifdwDDH4xWOaT1nongNCZUsiT3.2=.E2=.E2=.E2=.E2=.EwZbMCxYsi=5O4heOwF7MAF.EibUuaj2ECbjN4JYHoT3.2=.E2=.E2=.E2=.E2=.EwZbMCxYsi=5O4heOwF7OAF.EibUuaj2ECbjN4JYHoT3.2=.E2=.E2=.E2=.E2=.Ewxesi1jNC9UFqVfOaj2Hq12E29dsCdfl21dvqFZN2x5lE=.E2=.E2=.E2=.E2DDGKRXOKReNwI.E2=.E2=.E2=1noNjNCdcP43blE=.E2=.E2=.E2D0O49cMqZbPK=APqRWtCxXOwF4O4BguaF5lE=.E2=.E2=.E2=.E2D4NCxfNqxWOaT0uanWtAnDFWcXnoNYvqhbPq7eNw=1laHjOq1jNC9bmaPcMqmcOq1XOanXnoNYvqhUvqHWtwI.E2=.E2=.E2=.E2=1kixbPq7eNw9ePC9YnAx48WR0uanWtAnDFCfbPuZbMidYtqVXMwx0vqRjMadbk2D0vq1jNC9bmK11no9jMCxYsiT3.2=.E2=.E2=.Ewx0O49cMqZbPKT3.2=.E2=.Ewx2MqxgNwI.E2=.E2=1mKRXOKReM2RcOqdfl29ePC9YnAxAMKdgPKF5lE=.E2=.E2=.E2DAv4HdMC9bkwljMadbkwVBf06c6eUhfqX9mKH9euT1noljMadbkwxAv4HdMC9blE=.E2=.E2=.E2D7Nq1jNC9UFqVfOaj2GKH2E29dsCdfl2BdPC9hcCbjN4Jfd2x5lE=.E2=.E2=.E2DDOi9UvqHWs2RcOqdfl2xcl2=0uS1eOwF1OKnWvO1dvqFZOuFDFwI.E2=.E2=1noZbMqZbOaT3.2=.E2=.EwljNq9YvqBbk2D4NCxfNqxWOaT0uanWtAnDFCfbMwx4NCxfNqxWOaT.Ew9jNqxWOaT0uanWtAnDH43eP4pXno9jNqxWOaT.EwxAPqRWtCxXNwI.E2=.E2=1kaVWu4BdNqpUH4xbMiHjMqj2FaVXPCdYFwI.E2=.E2=.E2=1laHjOqRjMadbkidgsiHAnoHetqR0uanWtAnDFWcbEidgsiHAnoHetqydNq9eNCRcMqDDFaHjOqRjMadbk2D4NCxfMCxYsiTDMADDFaHjOq1jNC9blE=.E2=.E2=.E2D0vqRjMadbkidgsiHAnolVOalhMwx0vqRjMadbk2D0vq1jNC9bmKH1no9jMCxYsiT3.2=.E2=.Ewx0O49cMqZbPKT3.2=.Ewx2MqxgNwI.E2=1kCVYu4heMidYtwI.E2=.E2=1kixbPq7eNw9ePC9YnAx9O4ZbNo9ePC9YnAx2uiRbEidgsiHAnoMe6wx0vqRjMadbkw9jMCxYsiT5N4EYu4RgMKdgswx0vq1jNC9blE=.E2=.E2D4u4BeuaT1mKRWtwH1noZbMiT1noPcMqfeNwI.E2=1no1cNCVfOa9eNCT3.2=.Ew1cNCVfOa9eNCT3.2=.E2=.Ew9jNqxWOaT0uanWtAnDGqVdNqR0uanWtAnDFCfbNo9ePC9YnAx48WDDEixbPq7eNwD0vq1jNC9bn8hUsqng9qBXOalWuKxbMwx0vq1jNC9blE=.E2=.E2D4u4BeuaT1m4HYu4bbkw7cMiVblED4u4BeuaT1nC9YuKRiNwAUkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkmX17ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT17AAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAgkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkm917ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT18gAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAakmI5EwxAsiHdNqtbkwx4u4BeuaT3.wPcMqfeNwDAsiHdNqtbkmv17ER1nonWtCZbPaT1noPcMqfeNwI1liVXOidbkwnWtCZbPaT16QAZ=oDDHC9YuKRiNwDDFiVXOidblED4u4BeuaT1nC9YuKRiNwAdkmI5EwxAsiHdNqtbkwx4u4BeuaT3.wx0O49cNwDDG4HYu4bbkwx4u4BeuaT3.2=.Ewx.u4HcOqdWuaHblE=.E2D.u4HcOqdWuaHblE=.E2=.E2D0vqRjMadbkidgsiHAnohcOKRbEidgsiHAnoHetqR0uanWtAnDFWcbEidgsiHAnoHetqydNq9eNCRcMqDDEixbPq7eNwD0vq1jNC9bmKX1no9jMCxYsiT3.2=.E2=.EwPcMqfeNwDDN4JYuaNbkwVBf06c6eUhcmn17ER9euT1noxYNKHeNaT1noPcMqfeNwI.E2=1no1cNCVfOa9eNCT3.wx.tCxgNwI3'
1792
1793     fname="test_930.xml"
1794     with open(fname,"wb") as f:
1795       f.write( pilot.FromBase64Swig(content_of_file) )
1796
1797     SALOMERuntime.RuntimeSALOME_setRuntime()
1798     l=loader.YACSLoader()
1799     p=l.load(fname)
1800     self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").getChildByName("test23/run_internal").getInputPort("i1").getPyObj() == 3)
1801     self.assertTrue(p.getChildByName("test23/main").getChildByName("test23/run").getChildByName("test23/FE").edGetSeqOfSamplesPort().getPyObj()==list(range(10)))
1802     os.remove(fname)
1803     pass
1804
1805 if __name__ == '__main__':
1806   import os,sys
1807   U = os.getenv('USER')
1808   with open("/tmp/" + U + "/UnitTestsResult", 'a') as f:
1809       f.write("  --- TEST src/yacsloader: testSaveLoadRun.py\n")
1810       suite = unittest.makeSuite(TestSaveLoadRun)
1811       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
1812   sys.exit(not result.wasSuccessful())