2 # Copyright (C) 2006-2020 CEA/DEN, EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
29 dir_test = tempfile.mkdtemp(suffix=".yacstest")
31 class TestEdit(unittest.TestCase):
34 SALOMERuntime.RuntimeSALOME_setRuntime()
35 self.r = pilot.getRuntime()
36 self.l = loader.YACSLoader()
37 self.e = pilot.ExecutorSwig()
41 """ Test the conservation of the python context between two nodes sharing
48 proc=runtime.createProc("MySchema")
49 ti=proc.createType("int","int")
50 cont=proc.createContainer("MyContainer","Salome")
51 # type "multi" : the workload manager chooses the resource
52 # type "mono" : the resource is chosen by kernel, using the old rules.
53 cont.setProperty("type","multi")
54 # number of cores used by the container
55 cont.setProperty("nb_parallel_procs", "1")
56 n1=runtime.createScriptNode("","n1")
57 n2=runtime.createScriptNode("","n2")
58 n1.setExecutionMode("remote")
59 n2.setExecutionMode("remote")
63 res_port=n2.edAddOutputPort("v", ti)
66 proc.edAddCFLink(n1,n2)
67 # set the default execution mode using the workload manager
68 # if no property is set, the old executor is used
69 proc.setProperty("executor", "workloadmanager")
70 # reuse the same python context for every execution
71 cont.usePythonCache(True)
73 schema_file = os.path.join(dir_test,"pynode_with_cache1.xml")
74 proc.saveSchema(schema_file)
75 reloaded_proc = yacsloader.load(schema_file)
76 # default run method of the executor which uses the property "executor"
77 # in order to choose the actual run method
78 executor.RunW(reloaded_proc,0)
79 # you can also directly call the executor you wish, ignoring the property
80 #executor.RunB(proc,0) # always use the "old" executor
81 #executor.runWlm(proc,0) # always use the workload manager based executor
82 reloaded_res_port = reloaded_proc.getChildByName("n2").getOutputPort("v")
83 self.assertEqual(reloaded_res_port.getPyObj(), 42)
86 """ Same as test1, but using the old executor instead of workload manager.
91 proc=runtime.createProc("MySchema")
92 ti=proc.createType("int","int")
93 cont=proc.createContainer("MyContainer","Salome")
94 # With the old executor the type multi imposes the creation of a new
95 # container for every node. We need the type "mono" in order to have
96 # the same container used for both yacs nodes.
97 cont.setProperty("type","mono")
98 n1=runtime.createScriptNode("","n1")
99 n2=runtime.createScriptNode("","n2")
100 n1.setExecutionMode("remote")
101 n2.setExecutionMode("remote")
102 n1.setContainer(cont)
103 n2.setContainer(cont)
105 res_port=n2.edAddOutputPort("v", ti)
108 proc.edAddCFLink(n1,n2)
109 # reuse the same python context for every execution
110 cont.usePythonCache(True)
112 schema_file = os.path.join(dir_test,"pynode_with_cache2.xml")
113 proc.saveSchema(schema_file)
114 reloaded_proc = yacsloader.load(schema_file)
115 # default run method of the executor which uses the property "executor"
116 # in order to choose the actual run method
117 executor.RunW(reloaded_proc,0)
118 # you can also directly call the executor you wish, ignoring the property
119 #executor.RunB(proc,0) # always use the "old" executor
120 reloaded_res_port = reloaded_proc.getChildByName("n2").getOutputPort("v")
121 self.assertEqual(reloaded_res_port.getPyObj(), 42)
123 if __name__ == '__main__':
124 file_test = os.path.join(dir_test,"UnitTestsResult")
125 with open(file_test, 'a') as f:
126 f.write(" --- TEST src/yacsloader: testPynodeWithCache.py\n")
127 suite = unittest.makeSuite(TestEdit)
128 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
129 sys.exit(not result.wasSuccessful())