Salome HOME
suppresion d'un log
[tools/sat.git] / test / shell / test_shell.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
5 #  This library is free software; you can redistribute it and/or
6 #  modify it under the terms of the GNU Lesser General Public
7 #  License as published by the Free Software Foundation; either
8 #  version 2.1 of the License.
9 #
10 #  This library is distributed in the hope that it will be useful,
11 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 #  Lesser General Public License for more details.
14 #
15 #  You should have received a copy of the GNU Lesser General Public
16 #  License along with this library; if not, write to the Free Software
17 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18
19 import unittest
20 import os
21 import sys
22
23 # get execution path
24 testdir = os.path.dirname(os.path.realpath(__file__))
25 sys.path.append(os.path.join(testdir, '..', '..'))
26 sys.path.append(os.path.join(testdir, '..', '_testTools'))
27 sys.path.append(os.path.join(testdir, '..', '..','commands'))
28
29 from salomeTools import Sat
30 import HTMLTestRunner
31
32 class TestShell(unittest.TestCase):
33     '''Test of the shell command
34     '''
35
36     def test_shell(self):
37         '''Test the shell command with the --command option
38         '''
39         OK = 'KO'
40         tmp_file = "/tmp/test.txt"
41
42         sat = Sat("-l " + tmp_file)
43         
44         sat.config()
45         sat_way = sat.cfg.VARS.salometoolsway
46         
47         # Execute the shell command
48         sat.shell("--command ls " + sat_way)
49
50         ff = open(tmp_file, "r")
51         log_files = ff.readlines()
52         ff.close()
53         os.remove(tmp_file)
54         log_files = [line.replace("\n", "") for line in log_files]
55         
56         text = open(log_files[2], "r").read()
57
58         if "salomeTools.py" in text:
59             OK = 'OK'         
60         # pyunit method to compare 2 str
61         self.assertEqual(OK, 'OK')
62
63     def test_failing_shell(self):
64         '''Test the shell command with the --command option with a failing command
65         '''
66         OK = 'KO'
67         tmp_file = "/tmp/test.txt"
68
69         sat = Sat("-l " + tmp_file)
70         
71         sat.config()
72         
73         # Execute the shell command
74         res = sat.shell("--command i_fail")
75
76         ff = open(tmp_file, "r")
77         log_files = ff.readlines()
78         ff.close()
79         os.remove(tmp_file)
80         log_files = [line.replace("\n", "") for line in log_files]
81         
82         text = open(log_files[2], "r").read()
83
84         if "i_fail" in text and res == 1:
85             OK = 'OK'         
86         # pyunit method to compare 2 str
87         self.assertEqual(OK, 'OK')
88
89     def test_description(self):
90         '''Test the sat -h shell
91         '''        
92
93         OK = "KO"
94
95         import shell
96         
97         if "Executes the shell command passed as argument" in shell.description():
98             OK = "OK"
99
100         # pyunit method to compare 2 str
101         self.assertEqual(OK, "OK")
102
103 # test launch
104 if __name__ == '__main__':
105     HTMLTestRunner.main()