Salome HOME
Test for python node with cache.
[modules/yacs.git] / src / yacsloader_swig / Test / testWorkloadManager.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2006-2020  CEA/DEN, EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import sys
22 import pilot
23 import SALOMERuntime
24 import loader
25 import unittest
26 import tempfile
27 import os
28
29 class TestEdit(unittest.TestCase):
30
31     def setUp(self):
32         SALOMERuntime.RuntimeSALOME_setRuntime()
33         self.r = pilot.getRuntime()
34         self.l = loader.YACSLoader()
35         self.e = pilot.ExecutorSwig()
36         pass
37
38     def test1(self):
39       """ Test the conservation of the python context between two nodes sharing
40           the same container.
41           Schema: n1 -> n2
42       """
43       runtime=self.r
44       executor=self.e
45       proc=runtime.createProc("MySchema")
46       ti=proc.createType("int","int")
47       cont=proc.createContainer("MyContainer","Salome")
48       # type "multi" : the workload manager chooses the resource
49       # type "mono" : the workload manager does not choose the resource
50       cont.setProperty("type","multi")
51       # number of cores used by the container
52       cont.setProperty("nb_parallel_procs", "1")
53       n1=runtime.createScriptNode("","n1")
54       n2=runtime.createScriptNode("","n2")
55       n1.setExecutionMode("remote")
56       n2.setExecutionMode("remote")
57       n1.setContainer(cont)
58       n2.setContainer(cont)
59       n1.setScript("v=42")
60       res_port=n2.edAddOutputPort("v", ti)
61       proc.edAddChild(n1)
62       proc.edAddChild(n2)
63       proc.edAddCFLink(n1,n2)
64       # set the default execution mode using the workload manager
65       proc.setProperty("executor", "workloadmanager")
66       # reuse the same python context for every execution
67       cont.setStoreContext(True)
68       #proc.saveSchema("mini_wlm.xml")
69       executor=pilot.ExecutorSwig()
70       # default run method of the executor which uses the property "executor"
71       # in order to choose the actual run method
72       executor.RunW(proc,0)
73       # you can also impose the executor, ignoring the property "executor"
74       #executor.RunB(proc,0) # use the "historical" executor
75       #executor.runWlm(proc,0) # use the workload manager based executor
76       
77       self.assertEqual(res_port.getPyObj(), 42)
78
79 if __name__ == '__main__':
80   dir_test = tempfile.mkdtemp(suffix=".yacstest")
81   file_test = os.join(dir_test,"UnitTestsResult")
82   with open(file_test, 'a') as f:
83       f.write("  --- TEST src/yacsloader: testWorkloadManager.py\n")
84       suite = unittest.makeSuite(TestEdit)
85       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
86   sys.exit(not result.wasSuccessful())