4 # Copyright (C) 2010-2018 CEA/DEN
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.
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.
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
25 from src.salomeTools import Sat
27 from unittestpy.tools import outRedirection
29 class TestCase(unittest.TestCase):
30 """Test of the patch command"""
33 # Test the patch command with a product in dev mode
37 product_name = 'PRODUCT_DEV'
39 sat = Sat("-oUSER.output_level=2")
43 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
44 expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
45 expected_text = 'HELLO WORLD\n'
47 if os.path.exists(expected_src_dir):
48 shutil.rmtree(expected_src_dir)
50 sat.source(appli + ' --product ' + product_name)
52 f = open(expected_file_path, 'r')
53 text = f.readlines()[0]
55 if text == expected_text:
58 sat.patch(appli + ' --product ' + product_name)
60 new_expected_text = 'HELLO WORLD MODIFIED\n'
61 f = open(expected_file_path, 'r')
62 text = f.readlines()[0]
65 if text == new_expected_text:
68 if (OK1, OK2)==('OK', 'OK'):
70 self.assertEqual(OK, 'OK')
73 # Test the patch command with a product with no sources found
77 product_name = 'PRODUCT_DEV'
82 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
84 if os.path.exists(expected_src_dir):
85 shutil.rmtree(expected_src_dir)
88 my_out = outRedirection()
90 sat.patch(appli + ' --product ' + product_name)
92 # stop output redirection
93 my_out.end_redirection()
96 res = my_out.read_results()
98 if "No sources found for the " + product_name +" product" in res:
100 self.assertEqual(OK, 'OK')
103 # Test the patch command with a product without patch
107 product_name = 'PRODUCT_ARCHIVE'
111 sat.source(appli + ' --product ' + product_name)
114 my_out = outRedirection()
116 sat.patch(appli + ' --product ' + product_name)
118 # stop output redirection
119 my_out.end_redirection()
122 res = my_out.read_results()
124 if "No patch for the " + product_name +" product" in res:
126 self.assertEqual(OK, 'OK')
129 # Test the patch command with a product with a not valid patch
133 product_name = 'PRODUCT_DEV'
135 sat = Sat("-oPRODUCTS.PRODUCT_DEV.default.patches=['/']")
137 sat.source(appli + ' --product ' + product_name)
140 my_out = outRedirection()
142 sat.patch(appli + ' --product ' + product_name)
144 # stop output redirection
145 my_out.end_redirection()
148 res = my_out.read_results()
150 if "Not a valid patch" in res:
152 self.assertEqual(OK, 'OK')
155 # Test the sat -h patch
160 if "The patch command apply the patches on the sources of" in patch.description():
162 self.assertEqual(OK, "OK")
165 if __name__ == '__main__':