Salome HOME
Implementation of the project notion, remove all pyconf regardings the products from...
[tools/sat.git] / test / prepare / test_patch.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 TestPatch(unittest.TestCase):
38     '''Test of the patch command
39     '''
40
41     def test_patch_dev(self):
42         '''Test the patch command with a product in dev mode
43         '''
44         OK = 'KO'
45
46         appli = 'appli-test'
47         product_name = 'PRODUCT_DEV'
48
49         sat = Sat("-oUSER.output_level=2")
50                
51         sat.config(appli)
52         
53         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
54         expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
55         expected_text = 'HELLO WORLD\n'
56         
57         if os.path.exists(expected_src_dir):
58             shutil.rmtree(expected_src_dir)
59         
60         sat.source(appli + ' --product ' + product_name)
61         
62         f = open(expected_file_path, 'r')
63         text = f.readlines()[0]
64         OK1 = 'KO'
65         if text == expected_text:
66             OK1 = 'OK'
67        
68         sat.patch(appli + ' --product ' + product_name)
69         
70         new_expected_text = 'HELLO WORLD MODIFIED\n'
71         f = open(expected_file_path, 'r')
72         text = f.readlines()[0]
73         
74         OK2 = 'KO'
75         if text == new_expected_text:
76             OK2 = 'OK'         
77
78         if (OK1, OK2)==('OK', 'OK'):
79             OK = 'OK'
80
81         # pyunit method to compare 2 str
82         self.assertEqual(OK, 'OK')
83
84     def test_no_sources_found(self):
85         '''Test the patch command with a product with no sources found
86         '''
87         OK = 'KO'
88
89         appli = 'appli-test'
90         product_name = 'PRODUCT_DEV'
91
92         sat = Sat('')
93         sat.config(appli)
94         
95         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
96         
97         if os.path.exists(expected_src_dir):
98             shutil.rmtree(expected_src_dir)
99                
100         # output redirection
101         my_out = outRedirection()
102         
103         sat.patch(appli + ' --product ' + product_name)
104         
105         # stop output redirection
106         my_out.end_redirection()
107
108         # get results
109         res = my_out.read_results()
110         
111         if "No sources found for the " + product_name +" product" in res:
112             OK = 'OK'
113         
114         # pyunit method to compare 2 str
115         self.assertEqual(OK, 'OK')
116
117     def test_no_patch(self):
118         '''Test the patch command with a product without patch
119         '''
120         OK = 'KO'
121
122         appli = 'appli-test'
123         product_name = 'PRODUCT_ARCHIVE'
124
125         sat = Sat('-v4')
126                       
127         sat.source(appli + ' --product ' + product_name)
128                
129         # output redirection
130         my_out = outRedirection()
131         
132         sat.patch(appli + ' --product ' + product_name)
133         
134         # stop output redirection
135         my_out.end_redirection()
136
137         # get results
138         res = my_out.read_results()
139         
140         if "No patch for the " + product_name +" product" in res:
141             OK = 'OK'
142         
143         # pyunit method to compare 2 str
144         self.assertEqual(OK, 'OK')
145
146     def test_invalid_patch(self):
147         '''Test the patch command with a product with a not valid patch
148         '''
149         OK = 'KO'
150
151         appli = 'appli-test'
152         product_name = 'PRODUCT_DEV'
153
154         sat = Sat("-oPRODUCTS.PRODUCT_DEV.default.patches=['/']")
155                       
156         sat.source(appli + ' --product ' + product_name)
157                
158         # output redirection
159         my_out = outRedirection()
160         
161         sat.patch(appli + ' --product ' + product_name)
162         
163         # stop output redirection
164         my_out.end_redirection()
165
166         # get results
167         res = my_out.read_results()
168         
169         if "Not a valid patch" in res:
170             OK = 'OK'
171         
172         # pyunit method to compare 2 str
173         self.assertEqual(OK, 'OK')
174
175     def test_description(self):
176         '''Test the sat -h patch
177         '''        
178
179         OK = "KO"
180
181         import patch
182         
183         if "The patch command apply the patches on the sources of" in patch.description():
184             OK = "OK"
185
186         # pyunit method to compare 2 str
187         self.assertEqual(OK, "OK")
188
189 # test launch
190 if __name__ == '__main__':
191     HTMLTestRunner.main()