]> SALOME platform Git repositories - tools/sat.git/blob - test/prepare/test_source.py
Salome HOME
Improve test procedure for source, patch and prepare commands
[tools/sat.git] / test / prepare / test_source.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 import shutil
23
24 # get execution path
25 testdir = os.path.dirname(os.path.realpath(__file__))
26 sys.path.append(os.path.join(testdir, '..', '..'))
27 sys.path.append(os.path.join(testdir, '..', '_testTools'))
28 sys.path.append(os.path.join(testdir, '..', '..','commands'))
29
30 from tools import outRedirection
31
32 import src.product
33
34 from salomeTools import Sat
35 import HTMLTestRunner
36
37 class TestSource(unittest.TestCase):
38     '''Test of the source command
39     '''
40     
41     def test_source_archive(self):
42         '''Test the source command with archive product
43         '''
44         appli = 'appli-test'
45         product_name = 'PRODUCT_ARCHIVE'
46
47         sat = Sat()
48         sat.source(appli + ' --product ' + product_name)
49
50         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
51         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
52         expected_text = 'HELLO WORLD\n'
53
54         f = open(expected_file_path, 'r')
55         text = f.read()
56
57         # pyunit method to compare 2 str
58         self.assertEqual(text, expected_text)
59         
60     def test_source_git(self):
61         '''Test the source command with git product
62         '''
63         appli = 'appli-test'
64         product_name = 'PRODUCT_GIT'
65
66         sat = Sat()
67         sat.source(appli + ' --product ' + product_name)
68
69         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
70         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
71         expected_text = 'HELLO WORLD\n'
72
73         f = open(expected_file_path, 'r')
74         text = f.read()
75
76         # pyunit method to compare 2 str
77         self.assertEqual(text, expected_text)
78
79     def test_source_cvs(self):
80         '''Test the source command with cvs product
81         '''
82         appli = 'appli-test'
83         product_name = 'PRODUCT_CVS'
84
85         sat = Sat()
86         sat.source(appli + ' --product ' + product_name)
87
88         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
89         expected_file_path = os.path.join(expected_src_dir, 'README.FIRST.txt')
90         expected_text = 'Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE\n'
91
92         f = open(expected_file_path, 'r')
93         text = f.readlines()[0]
94
95         # pyunit method to compare 2 str
96         self.assertEqual(text, expected_text)
97     
98     """
99     def test_source_svn(self):
100         '''Test the source command with svn product
101         '''
102         OK = 'KO'
103         
104         appli = 'appli-test'
105         product_name = 'PRODUCT_SVN'
106
107         sat = Sat()
108         sat.source(appli + ' --product ' + product_name)
109
110         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
111         expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README')
112         expected_text = 'this directory contains scripts used by salomeTool'
113
114         f = open(expected_file_path, 'r')
115         text = f.readlines()[0]
116         
117         if expected_text in text:
118             OK = 'OK'
119          
120         # pyunit method to compare 2 str
121         self.assertEqual(OK, 'OK')
122     """
123
124     def test_source_native(self):
125         '''Test the source command with native product
126         '''
127         OK = 'KO'
128         
129         appli = 'appli-test'
130         product_name = 'PRODUCT_NATIVE'
131
132         sat = Sat()
133         sat.source(appli + ' --product ' + product_name)
134
135         expected_src_dir = os.path.join(sat.cfg.APPLICATION.out_dir, 'SOURCES', product_name)
136         if not os.path.exists(expected_src_dir):
137             OK = 'OK'
138
139         # pyunit method to compare 2 str
140         self.assertEqual(OK, 'OK')
141
142     def test_source_fixed(self):
143         '''Test the source command with fixed product
144         '''
145         OK = 'KO'
146         
147         appli = 'appli-test'
148         product_name = 'PRODUCT_FIXED'
149
150         sat = Sat()
151         sat.source(appli + ' --product ' + product_name)
152
153         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
154
155         if os.path.exists(expected_src_dir):
156             OK = 'OK'
157
158         # pyunit method to compare 2 str
159         self.assertEqual(OK, 'OK')
160         
161     def test_source_unknown(self):
162         '''Test the source command with unknown product
163         '''
164         OK = 'KO'
165
166         # output redirection
167         my_out = outRedirection()
168
169         appli = 'appli-test'
170         product_name = 'PRODUCT_UNKNOWN'
171
172         sat = Sat()
173         sat.source(appli + ' --product ' + product_name)
174
175         # stop output redirection
176         my_out.end_redirection()
177
178         # get results
179         res = my_out.read_results()
180
181         if "Unknown get source method" in res:
182             OK = 'OK'
183
184         # pyunit method to compare 2 str
185         self.assertEqual(OK, 'OK')
186
187     def test_source_dev(self):
188         '''Test the source command with a product in dev mode
189         '''
190         OK = 'KO'
191
192         appli = 'appli-test'
193         product_name = 'PRODUCT_DEV'
194
195         sat = Sat()
196                
197         sat.config(appli)
198         
199         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
200         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
201         expected_text = 'HELLO WORLD\n'
202         
203         if os.path.exists(expected_src_dir):
204             shutil.rmtree(expected_src_dir)
205         
206         sat.source(appli + ' --product ' + product_name)
207         
208         f = open(expected_file_path, 'r')
209         text = f.readlines()[0]
210         OK1 = 'KO'
211         if text == expected_text:
212             OK1 = 'OK'
213
214         # output redirection
215         my_out = outRedirection()
216         
217         sat.source(appli + ' --product ' + product_name)
218         
219         # stop output redirection
220         my_out.end_redirection()
221
222         # get results
223         res = my_out.read_results()
224
225         OK2 = 'KO'
226         if "source directory already exists" in res:
227             OK2 = 'OK'        
228
229         # output redirection
230         my_out = outRedirection()
231         
232         sat.source(appli + ' --product ' + product_name + ' --force')
233         
234         # stop output redirection
235         my_out.end_redirection()
236
237         # get results
238         res = my_out.read_results()
239
240         OK3 = 'KO'
241         if "source directory already exists" not in res:
242             OK3 = 'OK'         
243
244         if (OK1, OK2, OK3)==('OK', 'OK', 'OK'):
245             OK = 'OK'
246
247         # pyunit method to compare 2 str
248         self.assertEqual(OK, 'OK')
249
250     def test_description(self):
251         '''Test the sat -h source
252         '''        
253
254         OK = "KO"
255
256         import source
257         
258         if "gets the sources of the application" in source.description():
259             OK = "OK"
260
261         # pyunit method to compare 2 str
262         self.assertEqual(OK, "OK")
263
264 # test launch
265 if __name__ == '__main__':
266     HTMLTestRunner.main()