X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2Fyacsloader_swig%2FTest%2FtestSave.py;h=ccb3149bb8da4dc7e340f77e861d3abc9c643333;hb=1894c52d0838df8676e770bef061fc23ca436452;hp=bd39afb2e764b2960dd19f0e2cd0c8d30b584b09;hpb=668529b9cf7196cfc1cef53dc0ff1fa7a9d7f9e0;p=modules%2Fyacs.git diff --git a/src/yacsloader_swig/Test/testSave.py b/src/yacsloader_swig/Test/testSave.py index bd39afb2e..ccb3149bb 100755 --- a/src/yacsloader_swig/Test/testSave.py +++ b/src/yacsloader_swig/Test/testSave.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -# Copyright (C) 2006-2015 CEA/DEN, EDF R&D +#!/usr/bin/env python3 +# Copyright (C) 2006-2024 CEA, EDF # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -21,6 +21,8 @@ import time import unittest import threading +import tempfile +import os import SALOMERuntime import loader @@ -30,6 +32,7 @@ class TestSave(unittest.TestCase): def setUp(self): SALOMERuntime.RuntimeSALOME_setRuntime(1) + self.workdir = tempfile.mkdtemp(suffix=".yacstest") pass def test0_saveAndExec(self): @@ -53,11 +56,12 @@ class TestSave(unittest.TestCase): l = loader.YACSLoader() e = pilot.ExecutorSwig() for schema in schemaList: + print(schema) fileOrig = "samples/" + schema + ".xml" - saveSchema1 = "schema1_" + schema - dumpSchema1 = "dump1_" + schema - saveSchema2 = "schema2_" + schema - dumpSchema2 = "dump2_" + schema + saveSchema1 = os.path.join(self.workdir, "schema1_" + schema) + dumpSchema1 = os.path.join(self.workdir, "dump1_" + schema) + saveSchema2 = os.path.join(self.workdir, "schema2_" + schema) + dumpSchema2 = os.path.join(self.workdir, "dump2_" + schema) try: p = l.load(fileOrig) s = pilot.SchemaSave(p) @@ -69,37 +73,47 @@ class TestSave(unittest.TestCase): s.save(saveSchema2) e.RunW(p,0) e.saveState(dumpSchema2) - except ValueError, ex: - print "Value Error: ", ex + except ValueError as ex: + print("Value Error: ", ex) pb = "problem on " + fileOrig + " : ValueError" self.fail(pb) - except pilot.Exception,ex: - print ex.what() + except pilot.Exception as ex: + print(ex.what()) pb = "problem on " + fileOrig + " : " + ex.what() self.fail(pb) except: pb = "unknown problem on " + fileOrig self.fail(pb) - s1=open(saveSchema1,'r') - s2=open(saveSchema2,'r') - d1=open(dumpSchema1,'r') - d2=open(dumpSchema2,'r') - ls1 = s1.readlines().sort() - ls2 = s2.readlines().sort() - ld1 = d1.readlines().sort() - ld2 = d2.readlines().sort() + + with open(saveSchema1,'r') as s1: + ls1 = s1.readlines().sort() + with open(saveSchema2,'r') as s2: + ls2 = s2.readlines().sort() + with open(dumpSchema1,'r') as d1: + ld1 = d1.readlines().sort() + with open(dumpSchema2,'r') as d2: + ld2 = d2.readlines().sort() pb1 = "file schemes produced by successive executions are not identical: " + fileOrig pb2 = "final dump states produced by successive executions are not identical: " + fileOrig self.assertEqual(ls1,ls2,pb1) self.assertEqual(ld1,ld2,pb2) pass - -import os -U = os.getenv('USER') -f=open("/tmp/" + U + "/UnitTestsResult", 'a') -f.write(" --- TEST src/yacsloader: testSave.py\n") -suite = unittest.makeSuite(TestSave) -result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite) -f.close() -sys.exit(not result.wasSuccessful()) +if __name__ == '__main__': + import salome + import NamingService + import os + import subprocess + salome.salome_init() + ior = NamingService.NamingService.IOROfNS() + p = subprocess.Popen(["../yacsloader/echoSrv",ior]) + import time + time.sleep(3) + with tempfile.TemporaryDirectory(suffix=".yacstest") as dir_test: + file_test = os.path.join(dir_test,"UnitTestsResult") + with open(file_test, 'a') as f: + f.write(" --- TEST src/yacsloader: testSave.py\n") + suite = unittest.makeSuite(TestSave) + result=unittest.TextTestRunner(f, descriptions=1, verbosity=1).run(suite) + p.terminate() + sys.exit(not result.wasSuccessful())