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