4 # Copyright (C) 2010-2018 CEA/DEN
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.
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.
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
24 import initializeTest # set PATH etc for test
26 import src.salomeTools as SAT
27 import src.debug as DBG # Easy print stderr (for DEBUG only)
28 import src.loggingSimple as LOG
30 class TestCase(unittest.TestCase):
31 "Test the sat commands on APPLI_TEST configuration pyconf etc. files"""
35 #see test_100, # commands are expected OK
37 satCommandsToTestOk = [
41 "config %s --value ." % TRG,
42 "config %s --debug ." % TRG,
43 "config %s --info KERNEL" % TRG,
44 "config %s --show_patchs" % TRG,
46 #see test_110, # commands are expected KO
47 satCommandsToTestKo = [
48 "config %s --info oops" % TRG,
50 #see test_120, # commands are expected KO
51 satCommandsToTestRaise = [
52 "oopsconfig --oops .",
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)
66 logger = LOG.getUnittestLogger()
67 # one shot setUp() for this TestCase
68 if self.debug: DBG.push_debug(True)
69 SAT.setNotLocale() # test english
72 # one shot tearDown() for this TestCase
73 SAT.setLocale() # end test english
74 if self.debug: DBG.pop_debug()
77 logger = LOG.getUnittestLogger()
78 DBG.write("test_010 logger", logger.name)
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())
90 # test all satCommands expected OK
91 logger = LOG.getUnittestLogger()
93 for cmd in self.satCommandsToTestOk:
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)
104 # test all satCommands expected KO
105 logger = LOG.getUnittestLogger()
107 for cmd in self.satCommandsToTestKo:
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)
115 # test all satCommands expected raise
116 logger = LOG.getUnittestLogger()
118 for cmd in self.satCommandsToTestRaise:
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)
127 if __name__ == '__main__':
128 unittest.main(exit=False)