Salome HOME
add AllTestLauncher and src/loggingSimple.py etc...
[tools/sat.git] / test / test_500_APPLI_TEST.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 #  Copyright (C) 2010-2018  CEA/DEN
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19
20 import os
21 import sys
22 import unittest
23
24 import initializeTest # set PATH etc for test
25
26 import src.salomeTools as SAT
27 import src.debug as DBG # Easy print stderr (for DEBUG only)
28 import src.loggingSimple as LOG
29
30 class TestCase(unittest.TestCase):
31   "Test the sat commands on APPLI_TEST configuration pyconf etc. files"""
32
33   debug = False
34   
35   #see test_100, # commands are expected OK
36   TRG = "SALOME-8.4.0"
37   satCommandsToTestOk = [
38     "config -l",
39     "config -v .",
40     "config -g .",
41     "config %s --value ." %  TRG,
42     "config %s --debug ." %  TRG,
43     "config %s --info KERNEL" %  TRG,
44     "config %s --show_patchs" %  TRG,
45   ]
46   #see test_110, # commands are expected KO
47   satCommandsToTestKo = [
48     "config %s --info oops" %  TRG,
49   ]
50   #see test_120, # commands are expected KO
51   satCommandsToTestRaise = [
52     "oopsconfig --oops .",
53     "config --oops",
54   ]
55   
56   def tearDown(self):
57     # print "tearDown", __file__
58     # assure self.logger clear for next test
59     logger = LOG.getUnittestLogger()
60     logs = logger.getLogsAndClear()
61     # using assertNotIn() is too much verbose
62     self.assertFalse("ERROR    ::" in logs)
63     self.assertFalse("CRITICAL ::" in logs)
64
65   def test_000(self):
66     logger = LOG.getUnittestLogger()
67     # one shot setUp() for this TestCase
68     if self.debug: DBG.push_debug(True)
69     SAT.setNotLocale()  # test english
70
71   def test_999(self):
72     # one shot tearDown() for this TestCase
73     SAT.setLocale() # end test english
74     if self.debug: DBG.pop_debug()
75
76   def test_010(self):
77     logger = LOG.getUnittestLogger()
78     DBG.write("test_010 logger", logger.name)
79     cmd = "config -l"
80     s = SAT.Sat(logger)
81     DBG.write("s.getConfig()", s.getConfig()) #none
82     DBG.write("s.__dict__", s.__dict__) # have 
83     returnCode = s.execute_cli(cmd)
84     DBG.write("test_010", returnCode)
85     logs = logger.getLogs()
86     DBG.write("test_010 logger", logs)
87     self.assertTrue(returnCode.isOk())
88     
89   def test_100(self):
90     # test all satCommands expected OK
91     logger = LOG.getUnittestLogger()
92     dbg = self.debug
93     for cmd in self.satCommandsToTestOk:
94       s = SAT.Sat(logger)
95       returnCode = s.execute_cli(cmd)
96       DBG.write("test_100 'sat %s'" % cmd, str(returnCode), dbg)
97       logs = logger.getLogsAndClear()
98       DBG.write("logs", logs, dbg)
99       # using assertNotIn() is too much verbose
100       self.assertFalse("ERROR    ::" in logs)
101       self.assertFalse("CRITICAL ::" in logs)
102       
103   def xtest_110(self):
104     # test all satCommands expected KO
105     logger = LOG.getUnittestLogger()
106     dbg = self.debug
107     for cmd in self.satCommandsToTestKo:
108       s = SAT.Sat(logger)
109       returnCode = s.execute_cli(cmd)
110       DBG.write("test_110 'sat %s'" % cmd, returnCode, dbg)
111       logs = logger.getLogsAndClear()
112       DBG.write("logs", logs, dbg)    
113       
114   def xtest_120(self):
115     # test all satCommands expected raise
116     logger = LOG.getUnittestLogger()
117     dbg = self.debug
118     for cmd in self.satCommandsToTestRaise:
119       s = SAT.Sat(logger)
120       DBG.write("test_120 'sat %s'" % cmd, "expected raise", dbg)
121       with self.assertRaises(Exception):
122         returnCode = s.execute_cli(cmd)
123       logs = logger.getLogsAndClear()
124       DBG.write("logs", logs, dbg)    
125       
126       
127 if __name__ == '__main__':
128     unittest.main(exit=False)
129     pass