3 # Copyright (C) 2010-2012 CEA/DEN
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.
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.
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
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'))
30 from tools import outRedirection
34 from salomeTools import Sat
37 class TestPatch(unittest.TestCase):
38 '''Test of the patch command
41 def test_patch_dev(self):
42 '''Test the patch command with a product in dev mode
47 product_name = 'PRODUCT_DEV'
49 sat = Sat("-oUSER.output_level=2")
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'
57 if os.path.exists(expected_src_dir):
58 shutil.rmtree(expected_src_dir)
60 sat.source(appli + ' --product ' + product_name)
62 f = open(expected_file_path, 'r')
63 text = f.readlines()[0]
65 if text == expected_text:
68 sat.patch(appli + ' --product ' + product_name)
70 new_expected_text = 'HELLO WORLD MODIFIED\n'
71 f = open(expected_file_path, 'r')
72 text = f.readlines()[0]
75 if text == new_expected_text:
78 if (OK1, OK2)==('OK', 'OK'):
81 # pyunit method to compare 2 str
82 self.assertEqual(OK, 'OK')
84 def test_no_sources_found(self):
85 '''Test the patch command with a product with no sources found
90 product_name = 'PRODUCT_DEV'
95 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
97 if os.path.exists(expected_src_dir):
98 shutil.rmtree(expected_src_dir)
101 my_out = outRedirection()
103 sat.patch(appli + ' --product ' + product_name)
105 # stop output redirection
106 my_out.end_redirection()
109 res = my_out.read_results()
111 if "No sources found for the " + product_name +" product" in res:
114 # pyunit method to compare 2 str
115 self.assertEqual(OK, 'OK')
117 def test_no_patch(self):
118 '''Test the patch command with a product without patch
123 product_name = 'PRODUCT_ARCHIVE'
127 sat.source(appli + ' --product ' + product_name)
130 my_out = outRedirection()
132 sat.patch(appli + ' --product ' + product_name)
134 # stop output redirection
135 my_out.end_redirection()
138 res = my_out.read_results()
140 if "No patch for the " + product_name +" product" in res:
143 # pyunit method to compare 2 str
144 self.assertEqual(OK, 'OK')
146 def test_invalid_patch(self):
147 '''Test the patch command with a product with a not valid patch
152 product_name = 'PRODUCT_DEV'
154 sat = Sat("-oPRODUCTS.PRODUCT_DEV.default.patches=['/']")
156 sat.source(appli + ' --product ' + product_name)
159 my_out = outRedirection()
161 sat.patch(appli + ' --product ' + product_name)
163 # stop output redirection
164 my_out.end_redirection()
167 res = my_out.read_results()
169 if "Not a valid patch" in res:
172 # pyunit method to compare 2 str
173 self.assertEqual(OK, 'OK')
175 def test_description(self):
176 '''Test the sat -h patch
183 if "The patch command apply the patches on the sources of" in patch.description():
186 # pyunit method to compare 2 str
187 self.assertEqual(OK, "OK")
190 if __name__ == '__main__':
191 HTMLTestRunner.main()