Salome HOME
suppresion d'un log
[tools/sat.git] / test / prepare / test_clean.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 tools import outRedirection
30
31 from salomeTools import Sat
32 import HTMLTestRunner
33
34 import src.product
35
36 class TestClean(unittest.TestCase):
37     '''Test of the clean command
38     '''
39
40     def test_clean_no_args(self):
41         '''Test the clean command with no arguments (nothing to clean)
42         '''
43         OK = 'KO'
44
45         appli = 'appli-test'
46
47         sat = Sat()
48
49         # output redirection
50         my_out = outRedirection()
51         
52         sat.clean(appli)
53         
54         # stop output redirection
55         my_out.end_redirection()
56
57         # get results
58         res = my_out.read_results()
59         
60         if "Nothing to suppress" in res:
61             OK = 'OK'
62         
63         # pyunit method to compare 2 str
64         self.assertEqual(OK, 'OK')
65
66     def test_clean_sources(self):
67         '''Test the clean of sources
68         '''
69         OK = "KO"
70
71         appli = 'appli-test'
72         product_name = "PRODUCT_GIT"
73
74         sat = Sat()      
75         
76         # Make sure the sources exist
77         sat.prepare(appli + " -p " + product_name)
78         
79         # Call the command
80         sat.clean(appli + " -p " + product_name + " --sources", batch=True)
81            
82         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
83         
84         if not os.path.exists(expected_src_dir):
85             OK = "OK"
86         
87         # pyunit method to compare 2 str
88         self.assertEqual(OK, "OK")
89
90     def test_clean_build(self):
91         '''Test the clean of build
92         '''
93         OK = "KO"
94
95         appli = 'appli-test'
96         product_name = "PRODUCT_GIT"
97
98         sat = Sat()      
99         
100         # Make sure the build exists
101         sat.prepare(appli + " -p " + product_name)
102         sat.configure(appli + " -p " + product_name)
103         
104         # Call the command
105         sat.clean(appli + " -p " + product_name + " --build", batch=True)
106            
107         expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
108         
109         if not os.path.exists(expected_build_dir):
110             OK = "OK"
111         
112         # pyunit method to compare 2 str
113         self.assertEqual(OK, "OK")
114
115     def test_clean_install(self):
116         '''Test the clean of install
117         '''
118         OK = "KO"
119
120         appli = 'appli-test'
121         product_name = "PRODUCT_GIT"
122
123         sat = Sat()      
124         
125         # Make sure the build exists
126         sat.prepare(appli + " -p " + product_name)
127         sat.configure(appli + " -p " + product_name)
128         
129         # Call the command
130         sat.clean(appli + " -p " + product_name + " --install", batch=True)
131            
132         expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
133         
134         if not os.path.exists(expected_install_dir):
135             OK = "OK"
136         
137         # pyunit method to compare 2 str
138         self.assertEqual(OK, "OK")
139
140     def test_clean_all(self):
141         '''Test the clean of all (build, src, install)
142         '''
143         OK = "KO"
144
145         appli = 'appli-test'
146         product_name = "PRODUCT_GIT"
147
148         sat = Sat()      
149         
150         # Make sure the build exists
151         sat.prepare(appli + " -p " + product_name)
152         sat.compile(appli + " -p " + product_name)
153         
154         # Call the command
155         sat.clean(appli + " -p " + product_name + " --all", batch=True)
156            
157         expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
158         expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
159         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
160         
161         if not os.path.exists(expected_install_dir) and not os.path.exists(expected_build_dir) and not os.path.exists(expected_src_dir):
162             OK = "OK"
163         
164         # pyunit method to compare 2 str
165         self.assertEqual(OK, "OK")
166
167     def test_clean_sources_without_dev(self):
168         '''Test the clean with sources_without_dev option
169         '''
170         OK = "KO"
171
172         appli = 'appli-test'
173         product_name = "PRODUCT_GIT"
174         product_name2 = "PRODUCT_DEV"
175
176         sat = Sat()      
177         
178         # Make sure the build exists
179         sat.prepare(appli + " -p " + product_name + "," + product_name2)
180         
181         # Call the command
182         sat.clean(appli + " -p " + product_name + " --sources_without_dev", batch=True)
183            
184         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
185         expected_src_dir2 = src.product.get_product_config(sat.cfg, product_name2).source_dir
186         
187         if not os.path.exists(expected_src_dir) and os.path.exists(expected_src_dir2):
188             OK = "OK"
189         
190         # pyunit method to compare 2 str
191         self.assertEqual(OK, "OK")
192
193
194     def test_description(self):
195         '''Test the sat -h clean
196         '''        
197
198         OK = "KO"
199
200         import clean
201         
202         if "The clean command suppress the source, build, or install" in clean.description():
203             OK = "OK"
204
205         # pyunit method to compare 2 str
206         self.assertEqual(OK, "OK")
207
208 # test launch
209 if __name__ == '__main__':
210     HTMLTestRunner.main()