From ab421fb4ae3d4230a82f73e2120b6eaa7ae692b1 Mon Sep 17 00:00:00 2001 From: aguerre Date: Fri, 6 Sep 2013 16:15:42 +0000 Subject: [PATCH] test port manager --- .../tests/concurrentSession/CMakeLists.txt | 4 +- ...entSession.py => testConcurrentSession.py} | 52 +++++++++---------- 2 files changed, 26 insertions(+), 30 deletions(-) rename bin/appliskel/tests/concurrentSession/{TestConcurrentSession.py => testConcurrentSession.py} (61%) diff --git a/bin/appliskel/tests/concurrentSession/CMakeLists.txt b/bin/appliskel/tests/concurrentSession/CMakeLists.txt index 9c865f91a..137ddfe53 100644 --- a/bin/appliskel/tests/concurrentSession/CMakeLists.txt +++ b/bin/appliskel/tests/concurrentSession/CMakeLists.txt @@ -23,8 +23,8 @@ ENABLE_TESTING() # define environment for running tests SET(PYTHON_VERSION ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}) -SET(THIS_PYTHONPATH ${CMAKE_SOURCE_DIR}/bin/salome:$ENV{PYTHONPATH}) -#SET(THIS_LD_LIBRARY_PATH $ENV{CMAKE_SOURCE_DIR}/lib/salome:$ENV{LD_LIBRARY_PATH}) +SET(THIS_PYTHONPATH ${CMAKE_SOURCE_DIR}/bin:$ENV{PYTHONPATH}) +#SET(THIS_LD_LIBRARY_PATH $ENV{LD_LIBRARY_PATH}) # add tests (use make test to run) FILE(GLOB tests "${CMAKE_CURRENT_SOURCE_DIR}/Test*.py") diff --git a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py b/bin/appliskel/tests/concurrentSession/testConcurrentSession.py similarity index 61% rename from bin/appliskel/tests/concurrentSession/TestConcurrentSession.py rename to bin/appliskel/tests/concurrentSession/testConcurrentSession.py index 190226363..5b857cb98 100644 --- a/bin/appliskel/tests/concurrentSession/TestConcurrentSession.py +++ b/bin/appliskel/tests/concurrentSession/testConcurrentSession.py @@ -23,49 +23,45 @@ import sys import unittest import multiprocessing -class SalomeSession(object): - def __init__(self, script, killAtEnd=True): - self.__killAtEnd = killAtEnd - import runSalome - sys.argv = ["runSalome.py"] - sys.argv += ["--terminal"] - sys.argv += ["%s" % script] - clt, d = runSalome.main() +class TestConcurrentLaunch(unittest.TestCase): + @classmethod + def setUpClass(cls): + # Initialize path to SALOME application + path_to_launcher = os.getenv("SALOME_LAUNCHER") + appli_dir = os.path.dirname(path_to_launcher) + envd_dir = os.path.join(appli_dir, "env.d") + + # Configure session startup + cls.SALOME = imp.load_source("SALOME", os.path.join(appli_dir,"salome")) + cls.SALOME_args = ["shell", "--config="+envd_dir] # - def __del__(self): - if self.__killAtEnd: - port = os.getenv('NSPORT') - import killSalomeWithPort - killSalomeWithPort.killMyPort(port) - return + def session(self, args=[]): + self.SALOME.main(self.SALOME_args + args) # -# - -def run_session(): - SalomeSession("") -# -class TestConcurrentLaunch(unittest.TestCase): def testSingleSession(self): print "** Testing single session **" - SalomeSession("") + self.session() # def testMultiSession(self): print "** Testing multi sessions **" jobs = [] for i in range(3): - p = multiprocessing.Process(target=run_session) + p = multiprocessing.Process(target=session, args=(self,)) jobs.append(p) p.start() for j in jobs: j.join() # - @classmethod - def tearDownClass(cls): - import killSalome - killSalome.killAllPorts() - # # -unittest.main() + +if __name__ == "__main__": + path_to_launcher = os.getenv("SALOME_LAUNCHER") + if not path_to_launcher: + msg = "Error: please set SALOME_LAUNCHER variable to the salome command of your application folder." + raise Exception(msg) + + unittest.main() +# -- 2.39.2