]> SALOME platform Git repositories - modules/kernel.git/blob - bin/appliskel/tests/salomeCommand/TestLauncherSessionArgs_1.py
Salome HOME
fix failed tests
[modules/kernel.git] / bin / appliskel / tests / salomeCommand / TestLauncherSessionArgs_1.py
1 #!/usr/bin/env python3
2 # Copyright (C) 2013-2020  CEA/DEN, EDF R&D, OPEN CASCADE
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20
21 import unittest
22
23 import os
24 import sys
25 import imp
26 from io import StringIO
27 import logging
28
29 logger = logging.getLogger("TestLauncherLogger")
30 logger.level = logging.DEBUG
31 logger.addHandler(logging.StreamHandler())
32
33 class TestSessionArgs(unittest.TestCase):
34   #
35   @classmethod
36   def setUpClass(cls):
37     # Set some predefined command args and corresponding output messages
38     cls.hello0 = ["hello.py", "args:outfile=LOGFILE"]
39     cls.hello0Msg = "Hello!"
40     cls.hello1 = ["hello.py", "args:you,outfile=LOGFILE"]
41     cls.hello1Msg = "Hello to: you"
42     cls.helloToAdd = ["hello.py", "args:add.py,1,2,3,outfile=LOGFILE"]
43     cls.helloToAddMsg = "Hello to: add.py, 1, 2, 3"
44     cls.helloToList = ["hello.py", "args:['file1','file2'],1,2,3,[True,False],'ok',outfile=LOGFILE"]
45     cls.helloToListMsg = "Hello to: ['file1','file2'], 1, 2, 3, [True,False], 'ok'"
46     cls.add0 = ["add.py", "args:outfile=LOGFILE"]
47     cls.add0Msg = "No args!"
48     cls.add3 = ["add.py", "args:1,2,3,outfile=LOGFILE"]
49     cls.add3Msg = "1+2+3 = 6"
50     cls.lines0 = ["lines.py", "args:outfile=LOGFILE"]
51     cls.lines0Msg = "No files given"
52     cls.lines2 = ["lines.py", "args:hello.py,add.py,outfile=LOGFILE"]
53     cls.lines2Msg = "hello.py is 35 lines longadd.py is 37 lines long"
54     cls.linesUnreadable = ["lines.py", "args:hello.py,add.py,1,2,outfile=LOGFILE"]
55     cls.linesUnreadableMsg = "hello.py is 35 lines longadd.py is 37 lines longFile '1' cannot be readFile '2' cannot be read"
56     sys.stdout = StringIO()
57   #
58   def setUp(self):
59     import tempfile
60     from salomeContextUtils import setOmniOrbUserPath
61     setOmniOrbUserPath()
62     self.logFile = tempfile.NamedTemporaryFile()
63     if sys.platform == "win32": # Close file because of permission denined on Windows
64         self.logFile.close()
65   #
66   def tearDown(self):
67     self.logFile.close()
68   #
69   def session(self, args=None):
70     if args is None:
71       args = []
72     args = [x.replace("LOGFILE",self.logFile.name) for x in args]
73     try:
74       import setenv
75       setenv.main(True)
76       import runSession
77       params, args = runSession.configureSession(args, exe="salome shell")
78       return runSession.runSession(params, args)
79     except SystemExit as e:
80       if str(e) != '0':
81         logger.error(e)
82       import traceback
83       traceback.print_exc()
84       pass
85   #
86   def assertLogFileContentsEqual(self, message):
87     with open(self.logFile.name, "r") as f:
88       contents = f.read().replace('\n', '')
89
90     self.assertTrue(contents==message, "Contents differ!\n\tGenerated contents: %s\n\tExpected contents: %s"%(contents, message))
91   #
92   def testHello0(self):
93     self.session(self.hello0)
94     self.assertLogFileContentsEqual(self.hello0Msg)
95   #
96   def testPythonHello0(self):
97     self.session(["python"]+self.hello0)
98     self.assertLogFileContentsEqual(self.hello0Msg)
99   #
100   def testHello1(self):
101     self.session(self.hello1)
102     self.assertLogFileContentsEqual(self.hello1Msg)
103   #
104   def testAdd0(self):
105     self.session(self.add0)
106     self.assertLogFileContentsEqual(self.add0Msg)
107   #
108   def testAdd3(self):
109     self.session(self.add3)
110     self.assertLogFileContentsEqual(self.add3Msg)
111   #
112   def testHello0Add3(self):
113     self.session(self.hello0+self.add3)
114     self.assertLogFileContentsEqual(self.hello0Msg+self.add3Msg)
115   #
116   def testHello1Add3(self):
117     self.session(self.hello1+self.add3)
118     self.assertLogFileContentsEqual(self.hello1Msg+self.add3Msg)
119   #
120   def testHelloToAdd(self):
121     self.session(self.helloToAdd)
122     self.assertLogFileContentsEqual(self.helloToAddMsg)
123   #
124 #
125
126 if __name__ == "__main__":
127   unittest.main()
128 #