Salome HOME
'/usr/bin/env python' -> '/usr/bin/env python3'
[modules/yacs.git] / src / yacsloader_swig / Test / testResume.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2006-2016  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 time
22 import unittest
23 import threading
24
25 import SALOMERuntime
26 import loader
27 import pilot
28
29 class TestResume(unittest.TestCase):
30
31     def setUp(self):
32         SALOMERuntime.RuntimeSALOME_setRuntime(1)
33         self.l = loader.YACSLoader()
34         self.e = pilot.ExecutorSwig()
35         self.p = self.l.load("samples/bloc2.xml")
36         pass
37
38     def test1_PartialExec(self):
39         # --- stop execution after breakpoint
40         time.sleep(1)
41
42         print("================= Start of PARTIALEXEC ===================")
43         brp=['b1.b2.node1']
44         self.e.setListOfBreakPoints(brp)
45         self.e.setExecMode(2) # YACS::STOPBEFORENODES
46         #self.e.displayDot(self.p)
47         run1 = threading.Thread(None, self.e.RunPy, "breakpoint", (self.p,0))
48         run1.start()
49         time.sleep(0.1)
50         self.e.waitPause()
51         #self.e.displayDot(self.p)
52         self.e.saveState('dumpPartialBloc2.xml')
53         #self.e.displayDot(self.p)
54         self.e.stopExecution()
55         #self.e.displayDot(self.p)
56         self.assertEqual(101, self.p.getChildByName('b1.b2.node1').getEffectiveState())
57         self.assertEqual(106, self.p.getChildByName('b1.node1').getEffectiveState())
58         print("================= reach BREAKPOINT PARTIAL EXEC ==========")
59         pass
60
61     def test2_ExecFromLoadState(self):
62         # --- reload state from previous partial execution then exec
63         time.sleep(1)
64
65         print("================= Start of EXECLOADEDSTATE ===============")
66         sp = loader.stateParser()
67         sl = loader.stateLoader(sp,self.p)
68         sl.parse('dumpPartialBloc2.xml')
69         #self.e.displayDot(self.p)
70         self.e.setExecMode(0) # YACS::CONTINUE
71         run2 = threading.Thread(None, self.e.RunPy, "loadState", (self.p,0,True,True))
72         run2.start()
73         time.sleep(0.1)
74         self.e.waitPause()
75         #self.e.displayDot(self.p)
76         run2.join()
77         self.assertEqual(106, self.p.getChildByName('node1').getEffectiveState())
78         self.assertEqual(106, self.p.getChildByName('node2').getEffectiveState())
79         self.assertEqual(106, self.p.getChildByName('b1.node1').getEffectiveState())
80         self.assertEqual(106, self.p.getChildByName('b1.node2').getEffectiveState())
81         self.assertEqual(106, self.p.getChildByName('b1.b2.node1').getEffectiveState())
82         self.assertEqual(106, self.p.getChildByName('b1.b2.node2').getEffectiveState())
83         self.assertEqual(106, self.p.getChildByName('b1.b2.loop1.node1').getEffectiveState())
84         print("================= End of EXECLOADEDSTATE =================")
85                           
86     pass
87
88 if __name__ == '__main__':
89   import os
90   U = os.getenv('USER')
91   with open("/tmp/" + U + "/UnitTestsResult", 'a') as f:
92       f.write("  --- TEST src/yacsloader: testResume.py\n")
93       suite = unittest.makeSuite(TestResume)
94       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)
95   sys.exit(not result.wasSuccessful())