2 # Copyright (C) 2006-2022 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
30 dir_test = tempfile.mkdtemp(suffix=".yacstest")
32 class TestEdit(unittest.TestCase):
35 SALOMERuntime.RuntimeSALOME_setRuntime()
36 self.r = pilot.getRuntime()
37 self.l = loader.YACSLoader()
38 self.e = pilot.ExecutorSwig()
43 cm = salome.lcc.getContainerManager()
44 cm.ShutdownContainers()
47 """ Test the conservation of the python context between two nodes sharing
54 proc=runtime.createProc("MySchema")
55 ti=proc.createType("int","int")
56 cont=proc.createContainer("MyContainer","Salome")
57 # type "multi" : the workload manager chooses the resource
58 # type "mono" : the resource is chosen by kernel, using the old rules.
59 cont.setProperty("type","multi")
60 # number of cores used by the container
61 cont.setProperty("nb_parallel_procs", "1")
62 n1=runtime.createScriptNode("","n1")
63 n2=runtime.createScriptNode("","n2")
64 n1.setExecutionMode("remote")
65 n2.setExecutionMode("remote")
69 res_port=n2.edAddOutputPort("v", ti)
72 proc.edAddCFLink(n1,n2)
73 # set the default execution mode using the workload manager
74 # if no property is set, the old executor is used
75 proc.setProperty("executor", "workloadmanager")
76 # reuse the same python context for every execution
77 cont.usePythonCache(True)
79 schema_file = os.path.join(dir_test,"pynode_with_cache1.xml")
80 proc.saveSchema(schema_file)
81 reloaded_proc = yacsloader.load(schema_file)
82 # default run method of the executor which uses the property "executor"
83 # in order to choose the actual run method
84 executor.RunW(reloaded_proc,0)
85 # you can also directly call the executor you wish, ignoring the property
86 #executor.RunB(proc,0) # always use the "old" executor
87 #executor.runWlm(proc,0) # always use the workload manager based executor
88 reloaded_res_port = reloaded_proc.getChildByName("n2").getOutputPort("v")
89 self.assertEqual(reloaded_res_port.getPyObj(), 42)
92 """ Same as test1, but using the old executor instead of workload manager.
97 proc=runtime.createProc("MySchema")
98 ti=proc.createType("int","int")
99 cont=proc.createContainer("MyContainer","Salome")
100 # With the old executor the type multi imposes the creation of a new
101 # container for every node. We need the type "mono" in order to have
102 # the same container used for both yacs nodes.
103 cont.setProperty("type","mono")
104 n1=runtime.createScriptNode("","n1")
105 n2=runtime.createScriptNode("","n2")
106 n1.setExecutionMode("remote")
107 n2.setExecutionMode("remote")
108 n1.setContainer(cont)
109 n2.setContainer(cont)
111 res_port=n2.edAddOutputPort("v", ti)
114 proc.edAddCFLink(n1,n2)
115 # reuse the same python context for every execution
116 cont.usePythonCache(True)
118 schema_file = os.path.join(dir_test,"pynode_with_cache2.xml")
119 proc.saveSchema(schema_file)
120 reloaded_proc = yacsloader.load(schema_file)
121 # default run method of the executor which uses the property "executor"
122 # in order to choose the actual run method
123 executor.RunW(reloaded_proc,0)
124 # you can also directly call the executor you wish, ignoring the property
125 #executor.RunB(proc,0) # always use the "old" executor
126 reloaded_res_port = reloaded_proc.getChildByName("n2").getOutputPort("v")
127 self.assertEqual(reloaded_res_port.getPyObj(), 42)
129 if __name__ == '__main__':
130 file_test = os.path.join(dir_test,"UnitTestsResult")
131 with open(file_test, 'a') as f:
132 f.write(" --- TEST src/yacsloader: testPynodeWithCache.py\n")
133 suite = unittest.makeSuite(TestEdit)
134 result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
135 sys.exit(not result.wasSuccessful())