Salome HOME
style: black format
[tools/sat.git] / test / test_sat5_0 / compilation / test_compilation.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 src.product
25 from src.salomeTools import Sat
26
27
28 class TestCase(unittest.TestCase):
29     """Test of the compile command"""
30
31     def test_010(self):
32         # Test the compile command with '--products' option
33         OK = "KO"
34
35         appli = "appli-test"
36         product_name = "PRODUCT_GIT"
37
38         sat = Sat()
39
40         sat.prepare(appli + " --product " + product_name)
41         expected_install_dir = src.product.get_product_config(
42             sat.cfg, product_name
43         ).install_dir
44         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
45
46         sat.clean(appli + " --build --install --product " + product_name, batch=True)
47         sat.compile(appli + " --product " + product_name)
48
49         if os.path.exists(expected_file_path):
50             OK = "OK"
51         # pyunit method to compare 2 str
52         self.assertEqual(OK, "OK")
53
54     def test_020(self):
55         # Test the configure command with '--fathers' option
56         OK = "KO"
57
58         appli = "appli-test"
59         product_name = "PRODUCT_GIT"
60         product_name2 = "PRODUCT_ARCHIVE"
61
62         sat = Sat()
63
64         sat.prepare(appli + " --product " + product_name + "," + product_name2)
65         expected_install_dir = src.product.get_product_config(
66             sat.cfg, product_name
67         ).install_dir
68         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
69         expected_install_dir2 = src.product.get_product_config(
70             sat.cfg, product_name2
71         ).install_dir
72         expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
73
74         sat.clean(
75             appli
76             + " --build --install --product "
77             + product_name
78             + ","
79             + product_name2,
80             batch=True,
81         )
82         sat.compile(appli + " --with_fathers --product " + product_name)
83
84         if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
85             OK = "OK"
86         # pyunit method to compare 2 str
87         self.assertEqual(OK, "OK")
88
89     def test_030(self):
90         # Test the configure command with '--children' option
91         OK = "KO"
92
93         appli = "appli-test"
94         product_name = "PRODUCT_GIT"
95         product_name2 = "PRODUCT_ARCHIVE"
96
97         sat = Sat()
98
99         sat.prepare(appli + " --product " + product_name + "," + product_name2)
100         expected_install_dir = src.product.get_product_config(
101             sat.cfg, product_name
102         ).install_dir
103         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
104         expected_install_dir2 = src.product.get_product_config(
105             sat.cfg, product_name2
106         ).install_dir
107         expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
108
109         sat.clean(
110             appli
111             + " --build --install --product "
112             + product_name
113             + ","
114             + product_name2,
115             batch=True,
116         )
117         sat.compile(appli + " --with_children --product " + product_name2)
118
119         if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
120             OK = "OK"
121         # pyunit method to compare 2 str
122         self.assertEqual(OK, "OK")
123
124     def test_040(self):
125         # Test the configure command with '--clean_all' option
126         OK = "KO"
127
128         appli = "appli-test"
129         product_name = "PRODUCT_GIT"
130         product_name2 = "PRODUCT_ARCHIVE"
131
132         sat = Sat()
133
134         sat.prepare(appli + " --product " + product_name + "," + product_name2)
135         expected_install_dir = src.product.get_product_config(
136             sat.cfg, product_name
137         ).install_dir
138         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
139         expected_install_dir2 = src.product.get_product_config(
140             sat.cfg, product_name2
141         ).install_dir
142         expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
143
144         sat.compile(appli + " --with_children --product " + product_name2)
145
146         sat.compile(
147             appli + " --clean_all --with_children --product " + product_name2,
148             batch=True,
149         )
150
151         if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
152             OK = "OK"
153         # pyunit method to compare 2 str
154         self.assertEqual(OK, "OK")
155
156     def test_050(self):
157         # Test the configure command with '--clean_install' option
158         OK = "KO"
159
160         appli = "appli-test"
161         product_name = "PRODUCT_GIT"
162         product_name2 = "PRODUCT_ARCHIVE"
163
164         sat = Sat()
165
166         sat.prepare(appli + " --product " + product_name + "," + product_name2)
167         expected_install_dir = src.product.get_product_config(
168             sat.cfg, product_name
169         ).install_dir
170         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
171         expected_install_dir2 = src.product.get_product_config(
172             sat.cfg, product_name2
173         ).install_dir
174         expected_file_path2 = os.path.join(expected_install_dir2, "bin/hello-archive")
175
176         sat.compile(appli + " --with_children --product " + product_name2)
177
178         sat.compile(
179             appli + " --clean_install --with_children --product " + product_name2,
180             batch=True,
181         )
182
183         if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2):
184             OK = "OK"
185         # pyunit method to compare 2 str
186         self.assertEqual(OK, "OK")
187
188     def test_060(self):
189         # Test the configure command with '--make_flags' option
190         OK = "KO"
191
192         appli = "appli-test"
193         product_name = "PRODUCT_GIT"
194
195         sat = Sat()
196
197         sat.prepare(appli + " --product " + product_name)
198         expected_install_dir = src.product.get_product_config(
199             sat.cfg, product_name
200         ).install_dir
201         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
202
203         sat.clean(appli + " --build --install --product " + product_name, batch=True)
204         sat.compile(appli + " --make_flags 3 --product " + product_name)
205
206         if os.path.exists(expected_file_path):
207             OK = "OK"
208         # pyunit method to compare 2 str
209         self.assertEqual(OK, "OK")
210
211     def test_070(self):
212         # Test the configure command with '--show' option
213         OK = "KO"
214
215         appli = "appli-test"
216         product_name = "PRODUCT_GIT"
217
218         sat = Sat()
219
220         sat.prepare(appli + " --product " + product_name)
221         expected_install_dir = src.product.get_product_config(
222             sat.cfg, product_name
223         ).install_dir
224         expected_file_path = os.path.join(expected_install_dir, "bin/hello")
225
226         sat.clean(appli + " --build --install --product " + product_name, batch=True)
227         sat.compile(appli + " --show --product " + product_name)
228
229         if not (os.path.exists(expected_file_path)):
230             OK = "OK"
231         # pyunit method to compare 2 str
232         self.assertEqual(OK, "OK")
233
234     def test_080(self):
235         # Test the configure command with '--stop_first_fail' option
236         OK = "KO"
237
238         appli = "appli-test"
239
240         sat = Sat()
241
242         sat.prepare(appli + " --product PRODUCT_CVS,Python")
243         expected_install_dir = src.product.get_product_config(
244             sat.cfg, "PRODUCT_CVS"
245         ).install_dir
246
247         sat.clean(appli + " --build --install --product PRODUCT_CVS", batch=True)
248         sat.compile(appli + " --stop_first_fail --product PRODUCT_CVS,Python")
249
250         if not (os.path.exists(expected_install_dir)):
251             OK = "OK"
252         # pyunit method to compare 2 str
253         self.assertEqual(OK, "OK")
254
255     def test_090(self):
256         # Test the 'sat -h compile' command to get description
257
258         OK = "KO"
259
260         import compile
261
262         if "The compile command constructs the products" in compile.description():
263             OK = "OK"
264
265         # pyunit method to compare 2 str
266         self.assertEqual(OK, "OK")
267
268
269 # test launch
270 if __name__ == "__main__":
271     unittest.main()
272     pass