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
36 TRG = "APPLI_TEST" # "SALOME-8.4.0"
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,
51 # see test_120, # commands are expected Raise,
52 # but if fixed go to satCommandsToTestKo
53 satCommandsToTestRaise = [
54 "oopsconfig --oops .",
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)
67 logger = LOG.getUnittestLogger()
68 # one shot setUp() for this TestCase
69 if self.debug: DBG.push_debug(True)
70 SAT.setNotLocale() # test english
73 # one shot tearDown() for this TestCase
74 SAT.setLocale() # end test english
75 if self.debug: DBG.pop_debug()
78 logger = LOG.getUnittestLogger()
79 DBG.write("test_010 logger", logger.name)
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())
90 def xtest_100(self): # TODO
91 # test all satCommands expected OK
92 logger = LOG.getUnittestLogger()
94 for cmd in self.satCommandsToTestOk:
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)
105 # test all satCommands expected KO
106 logger = LOG.getUnittestLogger()
108 for cmd in self.satCommandsToTestKo:
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)
116 # test all satCommands expected raise
117 logger = LOG.getUnittestLogger()
119 for cmd in self.satCommandsToTestRaise:
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)
128 if __name__ == '__main__':
129 unittest.main(exit=False)