]> SALOME platform Git repositories - modules/yacs.git/blob - src/yacsloader_swig/Test/testValidationChecks.py
Salome HOME
More verifications on links in parallel loops.
[modules/yacs.git] / src / yacsloader_swig / Test / testValidationChecks.py
1 #! /usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 import unittest
5 import os
6 import sys
7 import pilot
8 import SALOMERuntime
9
10 class TestValidationChecks(unittest.TestCase):
11   def test_foreach_links(self):
12     """ Test tha add of illegal links within a foreach loop.
13     """
14     SALOMERuntime.RuntimeSALOME_setRuntime()
15     runtime = pilot.getRuntime()
16     
17     schema = runtime.createProc("schema")
18     ti=schema.getTypeCode("int")
19     tiset = schema.createSequenceTc("", "seqint", ti)
20
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")
26
27     ni = runtime.createScriptNode("", "Init")
28     ni.edAddInputPort("ii", ti)
29     ni.edAddOutputPort("oi", ti)
30     ni.setScript("o1=ii")
31
32     nf = runtime.createScriptNode("", "Fin")
33     nf.edAddInputPort("ifin", ti)
34     nf.edAddOutputPort("ofin", ti)
35     nf.setScript("ofin=ifin")
36
37     npre = runtime.createScriptNode("", "PreProc")
38     npre.edAddOutputPort("opre", ti)
39     npre.setScript("opre=5")
40
41     npost = runtime.createScriptNode("", "PostProc")
42     npost.edAddInputPort("ipost", ti)
43
44     fe = runtime.createForEachLoop("ForEach", ti)
45     fe.getInputPort("nbBranches").edInitPy(2)
46     fe.getInputPort("SmplsCollection").edInitPy([1, 2, 3, 4])
47     fe.edSetNode(nw)
48     fe.edSetInitNode(ni)
49     fe.edSetFinalizeNode(nf)
50     
51     schema.edAddChild(fe)
52     schema.edAddChild(npost)
53     
54     def excpTest(op, ip):
55       self.assertRaises(ValueError, schema.edAddLink, op, ip)
56       pass
57     
58     # ForEachLoop tests
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"))
75     
76   def test_optim_links(self):
77     """ Test tha add of illegal links within an optimization loop.
78     """
79     SALOMERuntime.RuntimeSALOME_setRuntime()
80     runtime = pilot.getRuntime()
81     #
82     schema = runtime.createProc("schema")
83     ti=schema.getTypeCode("int")
84     #
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")
90     #
91     ni = runtime.createScriptNode("", "Init")
92     ni.edAddInputPort("ii", ti)
93     ni.edAddOutputPort("oi", ti)
94     ni.setScript("o1=ii")
95     #
96     nf = runtime.createScriptNode("", "Fin")
97     nf.edAddInputPort("ifin", ti)
98     nf.edAddOutputPort("ofin", ti)
99     nf.setScript("ofin=ifin")
100     #
101     npre = runtime.createScriptNode("", "PreProc")
102     npre.edAddOutputPort("opre", ti)
103     npre.setScript("opre=5")
104     #
105     npost = runtime.createScriptNode("", "PostProc")
106     npost.edAddInputPort("ipost", ti)
107     #
108     fe = runtime.createOptimizerLoop("OptLoop", "optim_plugin.py","myalgosync",True)
109     fe.getInputPort("nbBranches").edInitPy(2)
110     fe.getInputPort("algoInit").edInitPy(7)
111     fe.edSetNode(nw)
112     fe.edSetInitNode(ni)
113     fe.edSetFinalizeNode(nf)
114     #
115     schema.edAddChild(fe)
116     schema.edAddChild(npost)
117     schema.edAddChild(npre)
118     
119     def excpTest(op, ip):
120       self.assertRaises(ValueError, schema.edAddLink, op, ip)
121       pass
122     
123     # ForEachLoop tests
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"))
150
151 if __name__ == '__main__':
152     unittest.main()