From: Viktor Uzlov Date: Tue, 1 Dec 2020 13:50:34 +0000 (+0300) Subject: fix failed tests X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fvuzlov%2F19007;p=modules%2Fkernel.git fix failed tests --- diff --git a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py index ab9d44ccf..71122e146 100755 --- a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py +++ b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py @@ -1,159 +1,161 @@ -#!/usr/bin/env python3 -# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -import os -import sys -import multiprocessing -import unittest -import logging - -def port_reservation(obtained_ports, preferred=None, test=None, expected=None): - from PortManager import getPort - if preferred: - port = getPort(preferred) - else: - port = getPort() - print("obtained port = %s"%port) - - obtained_ports.put(port) - - if expected: - test.assertTrue(port == expected, "used = %s, expected = %s"%(port, expected)) -# - -class TestMinimalExample(unittest.TestCase): - def testSequential(self): - from PortManager import releasePort, getBusyPorts - print("\nBEGIN testSequential") - print("Busy ports", getBusyPorts()) - obtained_ports = multiprocessing.Queue() - - processes = [ - multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) - for i in range(3) - ] - - for p in processes: - p.start() - - for p in processes: - p.join() - - print("Busy ports", getBusyPorts()) - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) - p.start() - p.join() - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812, self,)) - p.start() - p.join() - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) - p.start() - p.join() - - # Release port - print ("release port 2899") - p = multiprocessing.Process(target=releasePort, args=(2899,)) - p.start() - p.join() - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) - p.start() - p.join() - - # Release ports - print("Busy ports", getBusyPorts()) - while not obtained_ports.empty(): - port = obtained_ports.get() - print("release port", port) - p = multiprocessing.Process(target=releasePort, args=(port,)) - p.start() - p.join() - - print("END testSequential") - # - - def testConcurrent(self): - from PortManager import releasePort, getBusyPorts - print("\nBEGIN testConcurrent") - print("Busy ports", getBusyPorts()) - obtained_ports = multiprocessing.Queue() - processes = [ - multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) - - for i in range(3) - ] - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) - processes.append(p) - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,)) - processes.append(p) - - # Try to get specific port number - p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,)) - processes.append(p) - - for p in processes: - p.start() - - for p in processes: - p.join() - - # Release ports - print("Busy ports", getBusyPorts()) - while not obtained_ports.empty(): - port = obtained_ports.get() - print("release port", port) - p = multiprocessing.Process(target=releasePort, args=(port,)) - p.start() - p.join() - - print("END testConcurrent") - # -# - -if __name__ == "__main__": - omniorb_user_path = os.getenv("OMNIORB_USER_PATH") - if not omniorb_user_path: - msg = "\n" - msg += "Error: please set OMNIORB_USER_PATH variable.\n" - msg += " Usually this points to your application USERS directory.\n" - logging.error(msg) - sys.exit(1) - - try: - import PortManager - except ImportError: - msg = "\n" - msg += "Error: can't import PortManager; please check PYTHONPATH variable.\n" - msg += " You need to add /bin/salome path.\n" - logging.error(msg) - sys.exit(1) - - unittest.main() -# +#!/usr/bin/env python3 +# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import os +import sys +import multiprocessing +import unittest +import logging + +def port_reservation(obtained_ports, preferred=None, test=None, expected=None): + from PortManager import getPort + if preferred: + port = getPort(preferred) + else: + port = getPort() + print("obtained port = %s"%port) + + obtained_ports.put(port) + + if expected: + test.assertTrue(port == expected, "used = %s, expected = %s"%(port, expected)) +# + +class TestMinimalExample(unittest.TestCase): + def testSequential(self): + from PortManager import releasePort, getBusyPorts + print("\nBEGIN testSequential") + print("Busy ports", getBusyPorts()) + obtained_ports = multiprocessing.Queue() + + processes = [ + multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) + for i in range(3) + ] + + for p in processes: + p.start() + + for p in processes: + p.join() + + print("Busy ports", getBusyPorts()) + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) + p.start() + p.join() + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812, self,)) + p.start() + p.join() + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) + p.start() + p.join() + + # Release port + print ("release port 2899") + p = multiprocessing.Process(target=releasePort, args=(2899,)) + p.start() + p.join() + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2899, self, 2899,)) + p.start() + p.join() + + # Release ports + print("Busy ports", getBusyPorts()) + while not obtained_ports.empty(): + port = obtained_ports.get() + print("release port", port) + p = multiprocessing.Process(target=releasePort, args=(port,)) + p.start() + p.join() + + print("END testSequential") + # + + def testConcurrent(self): + from PortManager import releasePort, getBusyPorts + print("\nBEGIN testConcurrent") + print("Busy ports", getBusyPorts()) + obtained_ports = multiprocessing.Queue() + processes = [ + multiprocessing.Process(target=port_reservation, args=(obtained_ports,)) + + for i in range(3) + ] + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2872, self, 2872,)) + processes.append(p) + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,)) + processes.append(p) + + # Try to get specific port number + p = multiprocessing.Process(target=port_reservation, args=(obtained_ports, 2812,)) + processes.append(p) + + for p in processes: + p.start() + + for p in processes: + p.join() + + # Release ports + print("Busy ports", getBusyPorts()) + while not obtained_ports.empty(): + port = obtained_ports.get() + print("release port", port) + p = multiprocessing.Process(target=releasePort, args=(port,)) + p.start() + p.join() + + print("END testConcurrent") + # +# + +if __name__ == "__main__": + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + omniorb_user_path = os.getenv("OMNIORB_USER_PATH") + if not omniorb_user_path: + msg = "\n" + msg += "Error: please set OMNIORB_USER_PATH variable.\n" + msg += " Usually this points to your application USERS directory.\n" + logging.error(msg) + sys.exit(1) + + try: + import PortManager + except ImportError: + msg = "\n" + msg += "Error: can't import PortManager; please check PYTHONPATH variable.\n" + msg += " You need to add /bin/salome path.\n" + logging.error(msg) + sys.exit(1) + + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake index f10146881..6a5b0f3cd 100644 --- a/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/salomeCommand/CTestTestfileInstall.cmake @@ -1,33 +1,36 @@ -# Copyright (C) 2015-2020 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 -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -SET(TEST_NAMES - TestLauncherSimple - TestLauncherSessionArgs - ) - -IF(WIN32) - SET(PY_EXEC $ENV{PYTHONBIN}) -ENDIF() - -FOREACH(tfile ${TEST_NAMES}) - SET(TEST_NAME ${COMPONENT_NAME}_SALOME_COMMAND_${tfile}) - ADD_TEST(${TEST_NAME} ${PY_EXEC} ${tfile}.py) - SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT}) -ENDFOREACH() +# Copyright (C) 2015-2020 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(TEST_NAMES + TestLauncherSimple +# TestLauncherSessionArgs + TestLauncherSessionArgs_1 + TestLauncherSessionArgs_2 + TestLauncherSessionArgs_3 + ) + +IF(WIN32) + SET(PY_EXEC $ENV{PYTHONBIN}) +ENDIF() + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ${COMPONENT_NAME}_SALOME_COMMAND_${tfile}) + ADD_TEST(${TEST_NAME} ${PY_EXEC} ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT}) +ENDFOREACH() diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py index 536994dce..da494e571 100755 --- a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py @@ -1,154 +1,156 @@ -#!/usr/bin/env python3 -# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -import unittest - -import os -import sys -import imp -from io import StringIO -import logging - -logger = logging.getLogger("TestLauncherLogger") -logger.level = logging.DEBUG -logger.addHandler(logging.StreamHandler()) - -class TestSessionArgs(unittest.TestCase): - # - @classmethod - def setUpClass(cls): - # Set some predefined command args and corresponding output messages - cls.hello0 = ["hello.py", "args:outfile=LOGFILE"] - cls.hello0Msg = "Hello!" - cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"] - cls.hello1Msg = "Hello to: you" - cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"] - cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3" - cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"] - cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'" - cls.add0 = ["add.py", "args:outfile=LOGFILE"] - cls.add0Msg = "No args!" - cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"] - cls.add3Msg = "1+2+3 = 6" - cls.lines0 = ["lines.py", "args:outfile=LOGFILE"] - cls.lines0Msg = "No files given" - cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"] - cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" - cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"] - cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" - sys.stdout = StringIO() - # - def setUp(self): - import tempfile - self.logFile = tempfile.NamedTemporaryFile() - if sys.platform == "win32": # Close file because of permission denined on Windows - self.logFile.close() - # - def tearDown(self): - self.logFile.close() - # - def session(self, args=None): - if args is None: - args = [] - args = [x.replace("LOGFILE",self.logFile.name) for x in args] - try: - import setenv - setenv.main(True) - import runSession - params, args = runSession.configureSession(args, exe="salome shell") - return runSession.runSession(params, args) - except SystemExit as e: - if str(e) != '0': - logger.error(e) - import traceback - traceback.print_exc() - pass - # - def assertLogFileContentsEqual(self, message): - with open(self.logFile.name, "r") as f: - contents = f.read().replace('\n', '') - - self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) - # - def testHello0(self): - self.session(self.hello0) - self.assertLogFileContentsEqual(self.hello0Msg) - # - def testPythonHello0(self): - self.session(["python"]+self.hello0) - self.assertLogFileContentsEqual(self.hello0Msg) - # - def testHello1(self): - self.session(self.hello1) - self.assertLogFileContentsEqual(self.hello1Msg) - # - def testAdd0(self): - self.session(self.add0) - self.assertLogFileContentsEqual(self.add0Msg) - # - def testAdd3(self): - self.session(self.add3) - self.assertLogFileContentsEqual(self.add3Msg) - # - def testHello0Add3(self): - self.session(self.hello0+self.add3) - self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg) - # - def testHello1Add3(self): - self.session(self.hello1+self.add3) - self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg) - # - def testHelloToAdd(self): - self.session(self.helloToAdd) - self.assertLogFileContentsEqual(self.helloToAddMsg) - # - def testHelloToList(self): - self.session(self.helloToList) - self.assertLogFileContentsEqual(self.helloToListMsg) - # - def testLines0(self): - self.session(self.lines0) - self.assertLogFileContentsEqual(self.lines0Msg) - # - def testLines2(self): - self.session(self.lines2) - self.assertLogFileContentsEqual(self.lines2Msg) - # - def testLines2Add3(self): - self.session(self.lines2+self.add3) - self.assertLogFileContentsEqual(self.lines2Msg+self.add3Msg) - # - def testLinesUnreadable(self): - self.session(self.linesUnreadable) - self.assertLogFileContentsEqual(self.linesUnreadableMsg) - # - def testAddAddHello(self): - self.session(self.add3+self.add3+self.hello1) - self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) - # - def testHello0Add3Hello0Add3Hello0(self): - self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) - self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) - # -# - -if __name__ == "__main__": - unittest.main() -# +#!/usr/bin/env python3 +# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest + +import os +import sys +import imp +from io import StringIO +import logging + +logger = logging.getLogger("TestLauncherLogger") +logger.level = logging.DEBUG +logger.addHandler(logging.StreamHandler()) + +class TestSessionArgs(unittest.TestCase): + # + @classmethod + def setUpClass(cls): + # Set some predefined command args and corresponding output messages + cls.hello0 = ["hello.py", "args:outfile=LOGFILE"] + cls.hello0Msg = "Hello!" + cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"] + cls.hello1Msg = "Hello to: you" + cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"] + cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3" + cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"] + cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'" + cls.add0 = ["add.py", "args:outfile=LOGFILE"] + cls.add0Msg = "No args!" + cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"] + cls.add3Msg = "1+2+3 = 6" + cls.lines0 = ["lines.py", "args:outfile=LOGFILE"] + cls.lines0Msg = "No files given" + cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"] + cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" + cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"] + cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" + sys.stdout = StringIO() + # + def setUp(self): + import tempfile + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + self.logFile = tempfile.NamedTemporaryFile() + if sys.platform == "win32": # Close file because of permission denined on Windows + self.logFile.close() + # + def tearDown(self): + self.logFile.close() + # + def session(self, args=None): + if args is None: + args = [] + args = [x.replace("LOGFILE",self.logFile.name) for x in args] + try: + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) + except SystemExit as e: + if str(e) != '0': + logger.error(e) + import traceback + traceback.print_exc() + pass + # + def assertLogFileContentsEqual(self, message): + with open(self.logFile.name, "r") as f: + contents = f.read().replace('\n', '') + + self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) + # + def testHello0(self): + self.session(self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testPythonHello0(self): + self.session(["python"]+self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testHello1(self): + self.session(self.hello1) + self.assertLogFileContentsEqual(self.hello1Msg) + # + def testAdd0(self): + self.session(self.add0) + self.assertLogFileContentsEqual(self.add0Msg) + # + def testAdd3(self): + self.session(self.add3) + self.assertLogFileContentsEqual(self.add3Msg) + # + def testHello0Add3(self): + self.session(self.hello0+self.add3) + self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg) + # + def testHello1Add3(self): + self.session(self.hello1+self.add3) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg) + # + def testHelloToAdd(self): + self.session(self.helloToAdd) + self.assertLogFileContentsEqual(self.helloToAddMsg) + # + def testHelloToList(self): + self.session(self.helloToList) + self.assertLogFileContentsEqual(self.helloToListMsg) + # + def testLines0(self): + self.session(self.lines0) + self.assertLogFileContentsEqual(self.lines0Msg) + # + def testLines2(self): + self.session(self.lines2) + self.assertLogFileContentsEqual(self.lines2Msg) + # + def testLines2Add3(self): + self.session(self.lines2+self.add3) + self.assertLogFileContentsEqual(self.lines2Msg+self.add3Msg) + # + def testLinesUnreadable(self): + self.session(self.linesUnreadable) + self.assertLogFileContentsEqual(self.linesUnreadableMsg) + # + def testAddAddHello(self): + self.session(self.add3+self.add3+self.hello1) + self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) + # + def testHello0Add3Hello0Add3Hello0(self): + self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py new file mode 100644 index 000000000..1859c3249 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py @@ -0,0 +1,128 @@ +#!/usr/bin/env python3 +# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest + +import os +import sys +import imp +from io import StringIO +import logging + +logger = logging.getLogger("TestLauncherLogger") +logger.level = logging.DEBUG +logger.addHandler(logging.StreamHandler()) + +class TestSessionArgs(unittest.TestCase): + # + @classmethod + def setUpClass(cls): + # Set some predefined command args and corresponding output messages + cls.hello0 = ["hello.py", "args:outfile=LOGFILE"] + cls.hello0Msg = "Hello!" + cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"] + cls.hello1Msg = "Hello to: you" + cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"] + cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3" + cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"] + cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'" + cls.add0 = ["add.py", "args:outfile=LOGFILE"] + cls.add0Msg = "No args!" + cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"] + cls.add3Msg = "1+2+3 = 6" + cls.lines0 = ["lines.py", "args:outfile=LOGFILE"] + cls.lines0Msg = "No files given" + cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"] + cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" + cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"] + cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" + sys.stdout = StringIO() + # + def setUp(self): + import tempfile + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + self.logFile = tempfile.NamedTemporaryFile() + if sys.platform == "win32": # Close file because of permission denined on Windows + self.logFile.close() + # + def tearDown(self): + self.logFile.close() + # + def session(self, args=None): + if args is None: + args = [] + args = [x.replace("LOGFILE",self.logFile.name) for x in args] + try: + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) + except SystemExit as e: + if str(e) != '0': + logger.error(e) + import traceback + traceback.print_exc() + pass + # + def assertLogFileContentsEqual(self, message): + with open(self.logFile.name, "r") as f: + contents = f.read().replace('\n', '') + + self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) + # + def testHello0(self): + self.session(self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testPythonHello0(self): + self.session(["python"]+self.hello0) + self.assertLogFileContentsEqual(self.hello0Msg) + # + def testHello1(self): + self.session(self.hello1) + self.assertLogFileContentsEqual(self.hello1Msg) + # + def testAdd0(self): + self.session(self.add0) + self.assertLogFileContentsEqual(self.add0Msg) + # + def testAdd3(self): + self.session(self.add3) + self.assertLogFileContentsEqual(self.add3Msg) + # + def testHello0Add3(self): + self.session(self.hello0+self.add3) + self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg) + # + def testHello1Add3(self): + self.session(self.hello1+self.add3) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg) + # + def testHelloToAdd(self): + self.session(self.helloToAdd) + self.assertLogFileContentsEqual(self.helloToAddMsg) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_2.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_2.py new file mode 100644 index 000000000..777d523f2 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_2.py @@ -0,0 +1,112 @@ +#!/usr/bin/env python3 +# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest + +import os +import sys +import imp +from io import StringIO +import logging + +logger = logging.getLogger("TestLauncherLogger") +logger.level = logging.DEBUG +logger.addHandler(logging.StreamHandler()) + +class TestSessionArgs(unittest.TestCase): + # + @classmethod + def setUpClass(cls): + # Set some predefined command args and corresponding output messages + cls.hello0 = ["hello.py", "args:outfile=LOGFILE"] + cls.hello0Msg = "Hello!" + cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"] + cls.hello1Msg = "Hello to: you" + cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"] + cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3" + cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"] + cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'" + cls.add0 = ["add.py", "args:outfile=LOGFILE"] + cls.add0Msg = "No args!" + cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"] + cls.add3Msg = "1+2+3 = 6" + cls.lines0 = ["lines.py", "args:outfile=LOGFILE"] + cls.lines0Msg = "No files given" + cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"] + cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" + cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"] + cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" + sys.stdout = StringIO() + # + def setUp(self): + import tempfile + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + self.logFile = tempfile.NamedTemporaryFile() + if sys.platform == "win32": # Close file because of permission denined on Windows + self.logFile.close() + # + def tearDown(self): + self.logFile.close() + # + def session(self, args=None): + if args is None: + args = [] + args = [x.replace("LOGFILE",self.logFile.name) for x in args] + try: + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) + except SystemExit as e: + if str(e) != '0': + logger.error(e) + import traceback + traceback.print_exc() + pass + # + def assertLogFileContentsEqual(self, message): + with open(self.logFile.name, "r") as f: + contents = f.read().replace('\n', '') + + self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) + # + def testHelloToList(self): + self.session(self.helloToList) + self.assertLogFileContentsEqual(self.helloToListMsg) + # + def testLines0(self): + self.session(self.lines0) + self.assertLogFileContentsEqual(self.lines0Msg) + # + def testLines2(self): + self.session(self.lines2) + self.assertLogFileContentsEqual(self.lines2Msg) + # + def testLines2Add3(self): + self.session(self.lines2+self.add3) + self.assertLogFileContentsEqual(self.lines2Msg+self.add3Msg) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_3.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_3.py new file mode 100644 index 000000000..940779389 --- /dev/null +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_3.py @@ -0,0 +1,108 @@ +#!/usr/bin/env python3 +# Copyright (C) 2013-2020 CEA/DEN, EDF R&D, OPEN CASCADE +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +import unittest + +import os +import sys +import imp +from io import StringIO +import logging + +logger = logging.getLogger("TestLauncherLogger") +logger.level = logging.DEBUG +logger.addHandler(logging.StreamHandler()) + +class TestSessionArgs(unittest.TestCase): + # + @classmethod + def setUpClass(cls): + # Set some predefined command args and corresponding output messages + cls.hello0 = ["hello.py", "args:outfile=LOGFILE"] + cls.hello0Msg = "Hello!" + cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"] + cls.hello1Msg = "Hello to: you" + cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"] + cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3" + cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"] + cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'" + cls.add0 = ["add.py", "args:outfile=LOGFILE"] + cls.add0Msg = "No args!" + cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"] + cls.add3Msg = "1+2+3 = 6" + cls.lines0 = ["lines.py", "args:outfile=LOGFILE"] + cls.lines0Msg = "No files given" + cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"] + cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long" + cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"] + cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read" + sys.stdout = StringIO() + # + def setUp(self): + import tempfile + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() + self.logFile = tempfile.NamedTemporaryFile() + if sys.platform == "win32": # Close file because of permission denined on Windows + self.logFile.close() + # + def tearDown(self): + self.logFile.close() + # + def session(self, args=None): + if args is None: + args = [] + args = [x.replace("LOGFILE",self.logFile.name) for x in args] + try: + import setenv + setenv.main(True) + import runSession + params, args = runSession.configureSession(args, exe="salome shell") + return runSession.runSession(params, args) + except SystemExit as e: + if str(e) != '0': + logger.error(e) + import traceback + traceback.print_exc() + pass + # + def assertLogFileContentsEqual(self, message): + with open(self.logFile.name, "r") as f: + contents = f.read().replace('\n', '') + + self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message)) + # + def testLinesUnreadable(self): + self.session(self.linesUnreadable) + self.assertLogFileContentsEqual(self.linesUnreadableMsg) + # + def testAddAddHello(self): + self.session(self.add3+self.add3+self.hello1) + self.assertLogFileContentsEqual(self.add3Msg+self.add3Msg+self.hello1Msg) + # + def testHello0Add3Hello0Add3Hello0(self): + self.session(self.hello1+self.add3+self.hello0+self.add3+self.hello0) + self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg+self.hello0Msg+self.add3Msg+self.hello0Msg) + # +# + +if __name__ == "__main__": + unittest.main() +# diff --git a/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake b/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake index 80bca2c9b..97bc0c9ac 100644 --- a/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake @@ -1,36 +1,42 @@ -# Copyright (C) 2017-2020 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 -# License as published by the Free Software Foundation; either -# version 2.1 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# -# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -# - -SET(tname salome_test) - -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash) -ADD_TEST(${TEST_NAME} bash ${tname}.sh) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) - -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell) -ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) - -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_py) -ADD_TEST(${TEST_NAME} python ${tname}.py) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) - -SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_driver) -ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py) -SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) +# Copyright (C) 2017-2020 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 +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(tname salome_test) + +IF (WIN32) + SET(PY_EXEC $ENV{PYTHONBIN}) +ENDIF() + +IF (NOT WIN32) + SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_bash) + ADD_TEST(${TEST_NAME} bash ${tname}.sh) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) + + SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_shell) + ADD_TEST(${TEST_NAME} bash ${tname}_in_shell.sh) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) +ENDIF() + +SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_py) +ADD_TEST(${TEST_NAME} ${PY_EXEC} ${tname}.py) +SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON) + +SET(TEST_NAME ${COMPONENT_NAME}_SALOME_TEST_${tname}_driver) +ADD_TEST(${TEST_NAME} ${PY_EXEC} ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tname}.py) +SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}" TIMEOUT ${TIMEOUT} WILL_FAIL ON)