Salome HOME
evite la construction de l'environnement launch, saus pour la commande sat check
[tools/sat.git] / test / test_100_satHelp.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 --help commands"""
32   
33   debug = False
34   
35   def tearDown(self):
36     # print "tearDown", __file__
37     # assure self.logger clear for next test
38     logger = LOG.getUnittestLogger()
39     logs = logger.getLogsAndClear()
40     # using assertNotIn() is too much verbose
41     self.assertFalse("ERROR" in logs)
42     self.assertFalse("CRITICAL" in logs)
43   
44   def test_000(self):
45     logger = LOG.getUnittestLogger()
46     # one shot setUp() for this TestCase
47     if self.debug: DBG.push_debug(True)
48     SAT.setNotLocale() # test english
49
50   def test_999(self):
51     # one shot tearDown() for this TestCase
52     SAT.setLocale() # end test english
53     if self.debug: DBG.pop_debug()
54
55   def test_010(self): # TODO fix logger unittest
56     cmd = "sat --help"
57     res = SAT.launchSat(cmd)
58     self.assertTrue(res.isOk())
59     out = res.getValue()
60     self.assertTrue(" - config" in out)
61     self.assertTrue(" - prepare" in out)
62     self.assertTrue(" - compile" in out)
63
64   def test_011(self):
65     logger = LOG.getUnittestLogger()
66     cmd = "--help"
67     s = SAT.Sat(logger)
68     returnCode = s.execute_cli(cmd)
69     self.assertTrue(returnCode.isOk())
70     logs = logger.getLogs()
71     DBG.write("test_011 logger", logs)
72     self.assertTrue(" - config" in logs)
73     self.assertTrue(" - prepare" in logs)
74     self.assertTrue(" - compile" in logs)
75     
76   def test_030(self):
77     cmd = "sat config --help"
78     returnCode = SAT.launchSat(cmd)
79     self.assertTrue(returnCode.isOk())
80     out = returnCode.getValue()
81     DBG.write("test_030 stdout", out)
82     self.assertTrue("--value" in out)
83
84   def test_031(self):
85     logger = LOG.getUnittestLogger()
86     cmd = "config --help"
87     s = SAT.Sat(logger)
88     returnCode = s.execute_cli(cmd)
89     self.assertTrue(returnCode.isOk())
90     logs = logger.getLogs()
91     DBG.write("test_031 logger", logs)
92     self.assertTrue("--help" in logs)
93
94   def test_032(self):
95     logger = LOG.getUnittestLogger()
96     cmd = "prepare --help"
97     s = SAT.Sat(logger)
98     returnCode = s.execute_cli(cmd)
99     self.assertTrue(returnCode.isOk())
100     logs = logger.getLogs()
101     DBG.write("test_031 logger", logs)
102     self.assertTrue("--help" in logs)
103
104   def test_040(self):
105     logger = LOG.getUnittestLogger()
106     cmd = "config --list"
107     s = SAT.Sat(logger)
108     returnCode = s.execute_cli(cmd)
109     self.assertTrue(returnCode.isOk())
110     logs = logger.getLogs()
111     self.assertTrue("Applications" in logs)
112
113   def test_050(self):
114     cmds = SAT.getCommandsList()
115     DBG.write("test_050 getCommandsList", cmds)
116     for c in cmds:
117       cmd = "sat %s --help" % c
118       DBG.write("test_050", cmd)
119       returnCode = SAT.launchSat(cmd)
120       if not returnCode.isOk():
121         DBG.write("test_050 %s" % cmd, returnCode.getValue(), True)
122       self.assertTrue(returnCode.isOk())
123       out = returnCode.getValue()
124       DBG.write("test_050 %s stdout" % c, out)
125       self.assertTrue("The %s command" % c in out)
126       self.assertTrue("Available options" in out)
127       
128   def test_051(self):
129     logger = LOG.getUnittestLogger()
130     cmds = SAT.getCommandsList()
131     for c in cmds:
132       cmd = "%s --help" % c
133       DBG.write("test_051", cmd)
134       s = SAT.Sat(logger)
135       returnCode = s.execute_cli(cmd)
136       self.assertTrue(returnCode.isOk())
137       logs = logger.getLogsAndClear()
138       DBG.write(cmd, logs)
139       self.assertTrue("The %s command" % c in logs)
140       self.assertTrue("Available options" in logs)
141                 
142 if __name__ == '__main__':
143     unittest.main(exit=False)
144     pass