From c8c955453cce431f57c77fc1e80338ae5d2f5889 Mon Sep 17 00:00:00 2001 From: Viktor Uzlov Date: Tue, 1 Dec 2020 17:50:33 +0300 Subject: [PATCH] fix failed tests --- .../CTestTestfileInstall.cmake | 5 +- .../concurrentSession/TestMinimalExample.py | 2 + .../salomeCommand/TestLauncherSessionArgs.py | 2 + .../TestLauncherSessionArgs_1.py | 128 ++++++++++++++++++ .../TestLauncherSessionArgs_2.py | 112 +++++++++++++++ .../TestLauncherSessionArgs_3.py | 108 +++++++++++++++ .../salomeTest/CTestTestfileInstall.cmake | 18 ++- 7 files changed, 368 insertions(+), 7 deletions(-) create mode 100644 bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py create mode 100644 bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_2.py create mode 100644 bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_3.py diff --git a/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake b/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake index 5b333d6e6..7c37dd749 100644 --- a/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/concurrentSession/CTestTestfileInstall.cmake @@ -19,7 +19,10 @@ SET(TEST_NAMES TestMinimalExample - TestConcurrentSession +# TestLauncherSessionArgs + TestLauncherSessionArgs_1 + TestLauncherSessionArgs_2 + TestLauncherSessionArgs_3 ) IF (WIN32) diff --git a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py index ab9d44ccf..3afea6adf 100755 --- a/bin/appliskel/tests/concurrentSession/TestMinimalExample.py +++ b/bin/appliskel/tests/concurrentSession/TestMinimalExample.py @@ -138,6 +138,8 @@ class TestMinimalExample(unittest.TestCase): # if __name__ == "__main__": + from salomeContextUtils import setOmniOrbUserPath + setOmniOrbUserPath() omniorb_user_path = os.getenv("OMNIORB_USER_PATH") if not omniorb_user_path: msg = "\n" diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py index 536994dce..43ca0ef46 100755 --- a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py +++ b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs.py @@ -57,6 +57,8 @@ class TestSessionArgs(unittest.TestCase): # 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() diff --git a/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py b/bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py new file mode 100644 index 000000000..03995619f --- /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..705df6e08 --- /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..1978020a4 --- /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..4eea6ae2e 100644 --- a/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake +++ b/bin/appliskel/tests/salomeTest/CTestTestfileInstall.cmake @@ -19,13 +19,19 @@ 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) +IF (WIN32) + SET(PY_EXEC $ENV{PYTHONBIN}) +ENDIF() -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) +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} python ${tname}.py) -- 2.39.2