Salome HOME
set VARS.user to Unknown is USER var not set (no more exception), extend printings...
[tools/sat.git] / test / test_sat5_0 / prepare / test_clean.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 from src.salomeTools import Sat
25 import src.product
26 from unittestpy.tools import outRedirection
27
28 class TestCase(unittest.TestCase):
29     """Test of the clean command"""
30
31     def test_010(self):
32         # Test the clean command with no arguments (nothing to clean)
33         OK = 'KO'
34
35         appli = 'appli-test'
36
37         sat = Sat()
38
39         # output redirection
40         my_out = outRedirection()
41         
42         sat.clean(appli)
43         
44         # stop output redirection
45         my_out.end_redirection()
46
47         # get results
48         res = my_out.read_results()
49         
50         if "Nothing to suppress" in res:
51             OK = 'OK'
52         self.assertEqual(OK, 'OK')
53
54     def test_020(self):
55         # Test the clean of sources
56         OK = "KO"
57
58         appli = 'appli-test'
59         product_name = "PRODUCT_GIT"
60
61         sat = Sat()      
62         
63         # Make sure the sources exist
64         sat.prepare(appli + " -p " + product_name)
65         
66         # Call the command
67         sat.clean(appli + " -p " + product_name + " --sources", batch=True)
68            
69         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
70         
71         if not os.path.exists(expected_src_dir):
72             OK = "OK"
73         self.assertEqual(OK, "OK")
74
75     def test_030(self):
76         # Test the clean of build
77         OK = "KO"
78
79         appli = 'appli-test'
80         product_name = "PRODUCT_GIT"
81
82         sat = Sat()      
83         
84         # Make sure the build exists
85         sat.prepare(appli + " -p " + product_name)
86         sat.configure(appli + " -p " + product_name)
87         
88         # Call the command
89         sat.clean(appli + " -p " + product_name + " --build", batch=True)
90            
91         expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
92         
93         if not os.path.exists(expected_build_dir):
94             OK = "OK"
95         self.assertEqual(OK, "OK")
96
97     def test_040(self):
98         # Test the clean of install
99         OK = "KO"
100
101         appli = 'appli-test'
102         product_name = "PRODUCT_GIT"
103
104         sat = Sat()      
105         
106         # Make sure the build exists
107         sat.prepare(appli + " -p " + product_name)
108         sat.configure(appli + " -p " + product_name)
109         
110         # Call the command
111         sat.clean(appli + " -p " + product_name + " --install", batch=True)
112            
113         expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
114         
115         if not os.path.exists(expected_install_dir):
116             OK = "OK"
117         self.assertEqual(OK, "OK")
118
119     def test_050(self):
120         # Test the clean of all (build, src, install)
121         OK = "KO"
122
123         appli = 'appli-test'
124         product_name = "PRODUCT_GIT"
125
126         sat = Sat()      
127         
128         # Make sure the build exists
129         sat.prepare(appli + " -p " + product_name)
130         sat.compile(appli + " -p " + product_name)
131         
132         # Call the command
133         sat.clean(appli + " -p " + product_name + " --all", batch=True)
134            
135         expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
136         expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir
137         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
138         
139         if not os.path.exists(expected_install_dir) and not os.path.exists(expected_build_dir) and not os.path.exists(expected_src_dir):
140             OK = "OK"
141         self.assertEqual(OK, "OK")
142
143     def test_060(self):
144         # Test the clean with sources_without_dev option
145         OK = "KO"
146
147         appli = 'appli-test'
148         product_name = "PRODUCT_GIT"
149         product_name2 = "PRODUCT_DEV"
150
151         sat = Sat()      
152         
153         # Make sure the build exists
154         sat.prepare(appli + " -p " + product_name + "," + product_name2)
155         
156         # Call the command
157         sat.clean(appli + " -p " + product_name + " --sources_without_dev", batch=True)
158            
159         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
160         expected_src_dir2 = src.product.get_product_config(sat.cfg, product_name2).source_dir
161         
162         if not os.path.exists(expected_src_dir) and os.path.exists(expected_src_dir2):
163             OK = "OK"
164         self.assertEqual(OK, "OK")
165
166
167     def test_070(self):
168         # Test the sat -h clean
169         OK = "KO"
170
171         import clean
172         
173         if "The clean command suppress the source, build, or install" in clean.description():
174             OK = "OK"
175         self.assertEqual(OK, "OK")
176
177 # test launch
178 if __name__ == '__main__':
179     unittest.main()
180     pass