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