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 TestSource(unittest.TestCase):
38 '''Test of the source command
41 def test_source_archive(self):
42 '''Test the source command with archive product
45 product_name = 'PRODUCT_ARCHIVE'
48 sat.source(appli + ' --product ' + product_name)
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'
54 f = open(expected_file_path, 'r')
57 # pyunit method to compare 2 str
58 self.assertEqual(text, expected_text)
60 def test_source_git(self):
61 '''Test the source command with git product
64 product_name = 'PRODUCT_GIT'
67 sat.source(appli + ' --product ' + product_name)
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'
73 f = open(expected_file_path, 'r')
76 # pyunit method to compare 2 str
77 self.assertEqual(text, expected_text)
79 def test_source_cvs(self):
80 '''Test the source command with cvs product
83 product_name = 'PRODUCT_CVS'
86 sat.source(appli + ' --product ' + product_name)
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'
92 f = open(expected_file_path, 'r')
93 text = f.readlines()[0]
95 # pyunit method to compare 2 str
96 self.assertEqual(text, expected_text)
99 def test_source_svn(self):
100 '''Test the source command with svn product
105 product_name = 'PRODUCT_SVN'
108 sat.source(appli + ' --product ' + product_name)
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'
114 f = open(expected_file_path, 'r')
115 text = f.readlines()[0]
117 if expected_text in text:
120 # pyunit method to compare 2 str
121 self.assertEqual(OK, 'OK')
124 def test_source_native(self):
125 '''Test the source command with native product
130 product_name = 'PRODUCT_NATIVE'
133 sat.source(appli + ' --product ' + product_name)
135 expected_src_dir = os.path.join(sat.cfg.APPLICATION.out_dir, 'SOURCES', product_name)
136 if not os.path.exists(expected_src_dir):
139 # pyunit method to compare 2 str
140 self.assertEqual(OK, 'OK')
142 def test_source_fixed(self):
143 '''Test the source command with fixed product
148 product_name = 'PRODUCT_FIXED'
151 sat.source(appli + ' --product ' + product_name)
153 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
155 if os.path.exists(expected_src_dir):
158 # pyunit method to compare 2 str
159 self.assertEqual(OK, 'OK')
161 def test_source_unknown(self):
162 '''Test the source command with unknown product
167 my_out = outRedirection()
170 product_name = 'PRODUCT_UNKNOWN'
173 sat.source(appli + ' --product ' + product_name)
175 # stop output redirection
176 my_out.end_redirection()
179 res = my_out.read_results()
181 if "Unknown get source method" in res:
184 # pyunit method to compare 2 str
185 self.assertEqual(OK, 'OK')
187 def test_source_dev(self):
188 '''Test the source command with a product in dev mode
193 product_name = 'PRODUCT_DEV'
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'
203 if os.path.exists(expected_src_dir):
204 shutil.rmtree(expected_src_dir)
206 sat.source(appli + ' --product ' + product_name)
208 f = open(expected_file_path, 'r')
209 text = f.readlines()[0]
211 if text == expected_text:
215 my_out = outRedirection()
217 sat.source(appli + ' --product ' + product_name)
219 # stop output redirection
220 my_out.end_redirection()
223 res = my_out.read_results()
226 if "source directory already exists" in res:
230 my_out = outRedirection()
232 sat.source(appli + ' --product ' + product_name + ' --force')
234 # stop output redirection
235 my_out.end_redirection()
238 res = my_out.read_results()
241 if "source directory already exists" not in res:
244 if (OK1, OK2, OK3)==('OK', 'OK', 'OK'):
247 # pyunit method to compare 2 str
248 self.assertEqual(OK, 'OK')
250 def test_description(self):
251 '''Test the sat -h source
258 if "gets the sources of the application" in source.description():
261 # pyunit method to compare 2 str
262 self.assertEqual(OK, "OK")
265 if __name__ == '__main__':
266 HTMLTestRunner.main()