1 # Copyright (C) 2015-2016 CEA/DEN, EDF R&D
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.
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.
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
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 class TestEvalYFX(unittest.TestCase):
25 self.__buildScheme(fileName)
27 efx=evalyfx.YACSEvalYFX.BuildFromFile(fileName)
28 inps=efx.getFreeInputPorts()
29 self.assertEqual([elt.getName() for elt in inps],['a','b','e'])
30 self.assertEqual([elt.hasDefaultValueDefined() for elt in inps],[False,True,True])
31 self.assertAlmostEqual(inps[1].getDefaultValueDefined(),1.3,12)
32 self.assertAlmostEqual(inps[2].getDefaultValueDefined(),2.5,12)
34 inps[0].setDefaultValue(3.4)
35 self.assertEqual([elt.hasDefaultValueDefined() for elt in inps],[True,True,True])
36 self.assertAlmostEqual(inps[0].getDefaultValueDefined(),3.4,12)
38 inps[0].setDefaultValue(None)
39 self.assertEqual([elt.hasDefaultValueDefined() for elt in inps],[False,True,True])
40 inps[2].setDefaultValue(2.7)
41 self.assertAlmostEqual(inps[2].getDefaultValueDefined(),2.7,12)
42 inps[2].setDefaultValue(None)
43 self.assertEqual([elt.hasDefaultValueDefined() for elt in inps],[False,True,False])
44 self.assertRaises(ValueError,inps[0].getDefaultValueDefined)
45 self.assertAlmostEqual(inps[1].getDefaultValueDefined(),1.3,12)
46 self.assertRaises(ValueError,inps[2].getDefaultValueDefined)
48 outps=efx.getFreeOutputPorts()
49 self.assertEqual([elt.getName() for elt in outps],['c','f','g'])
50 # prepare for execution
51 inps[0].setDefaultValue(1.1)
52 inps[1].setSequenceOfValuesToEval([10.1,10.2,10.3])
53 self.assertRaises(ValueError,efx.lockPortsForEvaluation,[inps[1]],[outps[0],outps[2]]) # because e is not set
54 a=inps[2].hasSequenceOfValuesToEval()
55 self.assertTrue(not a)
56 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3,40.4])
57 a=inps[2].hasSequenceOfValuesToEval()
59 efx.lockPortsForEvaluation([inps[1],inps[2]],[outps[0],outps[2]])
60 inps[2].setSequenceOfValuesToEval([20.1,20.2,30.3])
62 g=efx.getUndergroundGeneratedGraph()
63 g.saveSchema("toto.xml")
68 def __buildScheme(self,fname):
71 SALOMERuntime.RuntimeSALOME.setRuntime()
72 r=SALOMERuntime.getSALOMERuntime()
74 td=p.createType("double","double")
76 cont=p.createContainer("zeCont","Salome")
78 n0=r.createFuncNode("Salome","node0")
82 n0.setScript("""def func0(a,b):
85 n0.setExecutionMode("remote")
86 a=n0.edAddInputPort("a",td)
87 b=n0.edAddInputPort("b",td) ; b.edInitPy(1.3)
88 c=n0.edAddOutputPort("c",td)
90 n1=r.createFuncNode("Salome","node1")
94 n1.setScript("""def func1(a,b):
97 n1.setExecutionMode("remote")
98 d=n1.edAddInputPort("d",td)
99 e=n1.edAddInputPort("e",td) ; e.edInitPy(2.5) # agy : useless but for test
100 f=n1.edAddOutputPort("f",td)
101 g=n1.edAddOutputPort("g",td)
110 if __name__ == '__main__':