Salome HOME
Add test for the compilation 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
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 from tools import outRedirection
30
31 import src.product
32
33 from salomeTools import Sat
34 import HTMLTestRunner
35
36 class TestSource(unittest.TestCase):
37     '''Test of the source command
38     '''
39     
40     def test_source_archive(self):
41         '''Test the source command with archive product
42         '''
43         appli = 'appli-test'
44         product_name = 'PRODUCT_ARCHIVE'
45
46         sat = Sat()
47         sat.source(appli + ' --product ' + product_name)
48
49         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
50         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
51         expected_text = 'HELLO WORLD\n'
52
53         f = open(expected_file_path, 'r')
54         text = f.read()
55
56         # pyunit method to compare 2 str
57         self.assertEqual(text, expected_text)
58         
59     def test_source_git(self):
60         '''Test the source command with git product
61         '''
62         appli = 'appli-test'
63         product_name = 'PRODUCT_GIT'
64
65         sat = Sat()
66         sat.source(appli + ' --product ' + product_name)
67
68         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
69         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
70         expected_text = 'HELLO WORLD\n'
71
72         f = open(expected_file_path, 'r')
73         text = f.read()
74
75         # pyunit method to compare 2 str
76         self.assertEqual(text, expected_text)
77
78     def test_source_cvs(self):
79         '''Test the source command with cvs product
80         '''
81         appli = 'appli-test'
82         product_name = 'PRODUCT_CVS'
83
84         sat = Sat()
85         sat.source(appli + ' --product ' + product_name)
86
87         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
88         expected_file_path = os.path.join(expected_src_dir, 'README.FIRST.txt')
89         expected_text = 'Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE\n'
90
91         f = open(expected_file_path, 'r')
92         text = f.readlines()[0]
93
94         # pyunit method to compare 2 str
95         self.assertEqual(text, expected_text)
96     
97     """
98     def test_source_svn(self):
99         '''Test the source command with svn product
100         '''
101         OK = 'KO'
102         
103         appli = 'appli-test'
104         product_name = 'PRODUCT_SVN'
105
106         sat = Sat()
107         sat.source(appli + ' --product ' + product_name)
108
109         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
110         expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README')
111         expected_text = 'this directory contains scripts used by salomeTool'
112
113         f = open(expected_file_path, 'r')
114         text = f.readlines()[0]
115         
116         if expected_text in text:
117             OK = 'OK'
118          
119         # pyunit method to compare 2 str
120         self.assertEqual(OK, 'OK')
121     """
122
123     def test_source_native(self):
124         '''Test the source command with native product
125         '''
126         OK = 'KO'
127         
128         appli = 'appli-test'
129         product_name = 'PRODUCT_NATIVE'
130
131         sat = Sat()
132         sat.source(appli + ' --product ' + product_name)
133
134         expected_src_dir = os.path.join(sat.cfg.APPLICATION.workdir, 'SOURCES', product_name)
135         if not os.path.exists(expected_src_dir):
136             OK = 'OK'
137
138         # pyunit method to compare 2 str
139         self.assertEqual(OK, 'OK')
140
141     def test_source_fixed(self):
142         '''Test the source command with fixed product
143         '''
144         OK = 'KO'
145         
146         appli = 'appli-test'
147         product_name = 'PRODUCT_FIXED'
148
149         sat = Sat()
150         sat.source(appli + ' --product ' + product_name)
151
152         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
153
154         if os.path.exists(expected_src_dir):
155             OK = 'OK'
156
157         # pyunit method to compare 2 str
158         self.assertEqual(OK, 'OK')
159     """    
160     def test_source_unknown(self):
161         '''Test the source command with unknown product
162         '''
163         OK = 'KO'
164
165         # output redirection
166         my_out = outRedirection()
167
168         appli = 'appli-test'
169         product_name = 'PRODUCT_UNKNOWN'
170
171         sat = Sat()
172         sat.source(appli + ' --product ' + product_name)
173
174         # stop output redirection
175         my_out.end_redirection()
176
177         # get results
178         res = my_out.read_results()
179
180         if "Unknown get source method" in res:
181             OK = 'OK'
182
183         # pyunit method to compare 2 str
184         self.assertEqual(OK, 'OK')
185     """
186
187     def test_description(self):
188         '''Test the sat -h source
189         '''        
190
191         OK = "KO"
192
193         import source
194         
195         if "gets the sources of the application" in source.description():
196             OK = "OK"
197
198         # pyunit method to compare 2 str
199         self.assertEqual(OK, "OK")
200
201 # test launch
202 if __name__ == '__main__':
203     HTMLTestRunner.main()