Salome HOME
Use tempfile.mkdtemp to create temporary directory
[modules/yacs.git] / src / yacsloader_swig / Test / testResume.py
index 3d6d0f0f6dd7781bf0b31c427478459ce24b23c8..d8dd3a6fa8cd6b8bbce9cc5cdaaa9f9753d1a010 100755 (executable)
@@ -1,5 +1,5 @@
 #!/usr/bin/env python3
-# Copyright (C) 2006-2019  CEA/DEN, EDF R&D
+# Copyright (C) 2006-2022  CEA/DEN, EDF R&D
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
 import time
 import unittest
 import threading
+import tempfile
+import os
 
 import SALOMERuntime
 import loader
 import pilot
+import salome
 
 class TestResume(unittest.TestCase):
 
@@ -33,8 +36,16 @@ class TestResume(unittest.TestCase):
         self.l = loader.YACSLoader()
         self.e = pilot.ExecutorSwig()
         self.p = self.l.load("samples/bloc2.xml")
+        workdir = tempfile.mkdtemp(suffix=".yacstest")
+        self.statefile = os.path.join(workdir, 'dumpPartialBloc2.xml')
         pass
 
+    def tearDown(self):
+      salome.salome_init()
+      cm = salome.lcc.getContainerManager()
+      cm.ShutdownContainers()
+      pass
+
     def test1_PartialExec(self):
         # --- stop execution after breakpoint
         time.sleep(1)
@@ -49,23 +60,21 @@ class TestResume(unittest.TestCase):
         time.sleep(0.1)
         self.e.waitPause()
         #self.e.displayDot(self.p)
-        self.e.saveState('dumpPartialBloc2.xml')
+        self.e.saveState(self.statefile)
         #self.e.displayDot(self.p)
         self.e.stopExecution()
         #self.e.displayDot(self.p)
         self.assertEqual(101, self.p.getChildByName('b1.b2.node1').getEffectiveState())
         self.assertEqual(106, self.p.getChildByName('b1.node1').getEffectiveState())
         print("================= reach BREAKPOINT PARTIAL EXEC ==========")
-        pass
 
-    def test2_ExecFromLoadState(self):
         # --- reload state from previous partial execution then exec
         time.sleep(1)
 
         print("================= Start of EXECLOADEDSTATE ===============")
         sp = loader.stateParser()
         sl = loader.stateLoader(sp,self.p)
-        sl.parse('dumpPartialBloc2.xml')
+        sl.parse(self.statefile)
         #self.e.displayDot(self.p)
         self.e.setExecMode(0) # YACS::CONTINUE
         run2 = threading.Thread(None, self.e.RunPy, "loadState", (self.p,0,True,True))
@@ -86,9 +95,9 @@ class TestResume(unittest.TestCase):
     pass
 
 if __name__ == '__main__':
-  import os
-  U = os.getenv('USER')
-  with open("/tmp/" + U + "/UnitTestsResult", 'a') as f:
+  dir_test = tempfile.mkdtemp(suffix=".yacstest")
+  file_test = os.path.join(dir_test,"UnitTestsResult")
+  with open(file_test, 'a') as f:
       f.write("  --- TEST src/yacsloader: testResume.py\n")
       suite = unittest.makeSuite(TestResume)
       result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite)