Salome HOME
Merge branch 'nct/may21'
[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 = "APPLI_TEST" # "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     "config --oops",
50   ]
51   # see test_120, # commands are expected Raise,
52   # but if fixed go to satCommandsToTestKo
53   satCommandsToTestRaise = [
54     "oopsconfig --oops .",
55   ]
56   
57   def tearDown(self):
58     # print "tearDown", __file__
59     # assure self.logger clear for next test
60     logger = LOG.getUnittestLogger()
61     logs = logger.getLogsAndClear()
62     # using assertNotIn() is too much verbose
63     self.assertFalse("ERROR    ::" in logs)
64     self.assertFalse("CRITICAL ::" in logs)
65
66   def test_000(self):
67     logger = LOG.getUnittestLogger()
68     # one shot setUp() for this TestCase
69     if self.debug: DBG.push_debug(True)
70     SAT.setNotLocale()  # test english
71
72   def test_999(self):
73     # one shot tearDown() for this TestCase
74     SAT.setLocale() # end test english
75     if self.debug: DBG.pop_debug()
76
77   def test_010(self):
78     logger = LOG.getUnittestLogger()
79     DBG.write("test_010 logger", logger.name)
80     cmd = "config -l"
81     s = SAT.Sat(logger)
82     DBG.write("s.getConfig()", s.getConfig()) #none
83     DBG.write("s.__dict__", s.__dict__) # have 
84     returnCode = s.execute_cli(cmd)
85     DBG.write("test_010", returnCode)
86     logs = logger.getLogs()
87     DBG.write("test_010 logger", logs)
88     self.assertTrue(returnCode.isOk())
89     
90   def xtest_100(self): # TODO
91     # test all satCommands expected OK
92     logger = LOG.getUnittestLogger()
93     dbg = self.debug
94     for cmd in self.satCommandsToTestOk:
95       s = SAT.Sat(logger)
96       returnCode = s.execute_cli(cmd)
97       DBG.write("test_100 'sat %s'" % cmd, str(returnCode), dbg)
98       logs = logger.getLogsAndClear()
99       DBG.write("logs", logs, dbg)
100       # using assertNotIn() is too much verbose
101       self.assertFalse("ERROR    ::" in logs)
102       self.assertFalse("CRITICAL ::" in logs)
103       
104   def test_110(self):
105     # test all satCommands expected KO
106     logger = LOG.getUnittestLogger()
107     dbg = self.debug
108     for cmd in self.satCommandsToTestKo:
109       s = SAT.Sat(logger)
110       returnCode = s.execute_cli(cmd)
111       DBG.write("test_110 'sat %s'" % cmd, returnCode, dbg)
112       logs = logger.getLogsAndClear()
113       DBG.write("logs", logs, dbg)    
114       
115   def test_120(self):
116     # test all satCommands expected raise
117     logger = LOG.getUnittestLogger()
118     dbg = self.debug
119     for cmd in self.satCommandsToTestRaise:
120       s = SAT.Sat(logger)
121       DBG.write("test_120 'sat %s'" % cmd, "expected raise", dbg)
122       with self.assertRaises(Exception):
123         returnCode = s.execute_cli(cmd)
124       logs = logger.getLogsAndClear()
125       DBG.write("logs", logs, dbg)    
126       
127       
128 if __name__ == '__main__':
129     unittest.main(exit=False)
130     pass