2 # -*- coding: utf-8 -*-
10 class TestValidationChecks(unittest.TestCase):
11 def test_foreach_links(self):
12 """ Test tha add of illegal links within a foreach loop.
14 SALOMERuntime.RuntimeSALOME_setRuntime()
15 runtime = pilot.getRuntime()
17 schema = runtime.createProc("schema")
18 ti=schema.getTypeCode("int")
19 tiset = schema.createSequenceTc("", "seqint", ti)
21 nw = runtime.createScriptNode("", "Worker")
22 nw.edAddInputPort("i1", ti)
23 nw.edAddInputPort("i2", ti)
24 nw.edAddOutputPort("o1", ti)
25 nw.setScript("o1=i1+i2")
27 ni = runtime.createScriptNode("", "Init")
28 ni.edAddInputPort("ii", ti)
29 ni.edAddOutputPort("oi", ti)
32 nf = runtime.createScriptNode("", "Fin")
33 nf.edAddInputPort("ifin", ti)
34 nf.edAddOutputPort("ofin", ti)
35 nf.setScript("ofin=ifin")
37 npre = runtime.createScriptNode("", "PreProc")
38 npre.edAddOutputPort("opre", ti)
39 npre.setScript("opre=5")
41 npost = runtime.createScriptNode("", "PostProc")
42 npost.edAddInputPort("ipost", ti)
44 fe = runtime.createForEachLoop("ForEach", ti)
45 fe.getInputPort("nbBranches").edInitPy(2)
46 fe.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
49 fe.edSetFinalizeNode(nf)
52 schema.edAddChild(npost)
55 self.assertRaises(ValueError, schema.edAddLink, op, ip)
59 excpTest(fe.getOutputPort("evalSamples"), npost.getInputPort("ipost"))
60 excpTest(fe.getOutputPort("evalSamples"), ni.getInputPort("ii"))
61 excpTest(fe.getOutputPort("evalSamples"), nf.getInputPort("ifin"))
62 excpTest(fe.getOutputPort("evalSamples"), fe.getInputPort("nbBranches"))
63 excpTest(ni.getOutputPort("oi"), fe.getInputPort("nbBranches"))
64 excpTest(nw.getOutputPort("o1"), fe.getInputPort("nbBranches"))
65 excpTest(nf.getOutputPort("ofin"), fe.getInputPort("nbBranches"))
66 excpTest(fe.getOutputPort("evalSamples"), fe.getInputPort("SmplsCollection"))
67 excpTest(ni.getOutputPort("oi"), fe.getInputPort("SmplsCollection"))
68 excpTest(nw.getOutputPort("o1"), fe.getInputPort("SmplsCollection"))
69 excpTest(nf.getOutputPort("ofin"), fe.getInputPort("SmplsCollection"))
70 excpTest(nw.getOutputPort("o1"), nf.getInputPort("ifin"))
71 excpTest(nw.getOutputPort("o1"), ni.getInputPort("ii"))
72 excpTest(ni.getOutputPort("oi"), npost.getInputPort("ipost"))
73 excpTest(nf.getOutputPort("ofin"), npost.getInputPort("ipost"))
74 excpTest(nf.getOutputPort("ofin"), ni.getInputPort("ii"))
76 def test_optim_links(self):
77 """ Test tha add of illegal links within an optimization loop.
79 SALOMERuntime.RuntimeSALOME_setRuntime()
80 runtime = pilot.getRuntime()
82 schema = runtime.createProc("schema")
83 ti=schema.getTypeCode("int")
85 nw = runtime.createScriptNode("", "Worker")
86 nw.edAddInputPort("i1", ti)
87 nw.edAddInputPort("i2", ti)
88 nw.edAddOutputPort("o1", ti)
89 nw.setScript("o1=i1+i2")
91 ni = runtime.createScriptNode("", "Init")
92 ni.edAddInputPort("ii", ti)
93 ni.edAddOutputPort("oi", ti)
96 nf = runtime.createScriptNode("", "Fin")
97 nf.edAddInputPort("ifin", ti)
98 nf.edAddOutputPort("ofin", ti)
99 nf.setScript("ofin=ifin")
101 npre = runtime.createScriptNode("", "PreProc")
102 npre.edAddOutputPort("opre", ti)
103 npre.setScript("opre=5")
105 npost = runtime.createScriptNode("", "PostProc")
106 npost.edAddInputPort("ipost", ti)
108 fe = runtime.createOptimizerLoop("OptLoop", "optim_plugin.py","myalgosync",True)
109 fe.getInputPort("nbBranches").edInitPy(2)
110 fe.getInputPort("algoInit").edInitPy(7)
113 fe.edSetFinalizeNode(nf)
115 schema.edAddChild(fe)
116 schema.edAddChild(npost)
117 schema.edAddChild(npre)
119 def excpTest(op, ip):
120 self.assertRaises(ValueError, schema.edAddLink, op, ip)
124 excpTest(fe.getOutputPort("evalSamples"), npost.getInputPort("ipost"))
125 excpTest(fe.getOutputPort("evalSamples"), ni.getInputPort("ii"))
126 excpTest(fe.getOutputPort("evalSamples"), nf.getInputPort("ifin"))
127 excpTest(fe.getOutputPort("evalSamples"), fe.getInputPort("nbBranches"))
128 excpTest(nw.getOutputPort("o1"), nf.getInputPort("ifin"))
129 excpTest(nw.getOutputPort("o1"), ni.getInputPort("ii"))
130 excpTest(ni.getOutputPort("oi"), npost.getInputPort("ipost"))
131 excpTest(nf.getOutputPort("ofin"), npost.getInputPort("ipost"))
132 excpTest(nf.getOutputPort("ofin"), ni.getInputPort("ii"))
133 # Specific OptimizerLoop tests
134 excpTest(nw.getOutputPort("o1"), fe.getInputPort("nbBranches"))
135 excpTest(ni.getOutputPort("oi"), fe.getInputPort("nbBranches"))
136 excpTest(nf.getOutputPort("ofin"), fe.getInputPort("nbBranches"))
137 excpTest(nw.getOutputPort("o1"), fe.getInputPort("algoInit"))
138 excpTest(ni.getOutputPort("oi"), fe.getInputPort("algoInit"))
139 excpTest(nf.getOutputPort("ofin"), fe.getInputPort("algoInit"))
140 excpTest(ni.getOutputPort("oi"), fe.getInputPort("evalResults"))
141 excpTest(nf.getOutputPort("ofin"), fe.getInputPort("evalResults"))
142 excpTest(npre.getOutputPort("opre"), fe.getInputPort("evalResults"))
143 excpTest(fe.getOutputPort("evalSamples"), fe.getInputPort("algoInit"))
144 excpTest(fe.getOutputPort("algoResults"), nw.getInputPort("i1"))
145 excpTest(fe.getOutputPort("algoResults"), ni.getInputPort("ii"))
146 excpTest(fe.getOutputPort("algoResults"), nf.getInputPort("ifin"))
147 excpTest(nw.getOutputPort("o1"), npost.getInputPort("ipost"))
148 excpTest(ni.getOutputPort("oi"), npost.getInputPort("ipost"))
149 excpTest(nf.getOutputPort("ofin"), npost.getInputPort("ipost"))
151 if __name__ == '__main__':