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