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
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'))
29 from tools import outRedirection
33 from salomeTools import Sat
36 class TestSource(unittest.TestCase):
37 '''Test of the source command
40 def test_source_archive(self):
41 '''Test the source command with archive product
44 product_name = 'PRODUCT_ARCHIVE'
47 sat.source(appli + ' --product ' + product_name)
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'
53 f = open(expected_file_path, 'r')
56 # pyunit method to compare 2 str
57 self.assertEqual(text, expected_text)
59 def test_source_git(self):
60 '''Test the source command with git product
63 product_name = 'PRODUCT_GIT'
66 sat.source(appli + ' --product ' + product_name)
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'
72 f = open(expected_file_path, 'r')
75 # pyunit method to compare 2 str
76 self.assertEqual(text, expected_text)
78 def test_source_cvs(self):
79 '''Test the source command with cvs product
82 product_name = 'PRODUCT_CVS'
85 sat.source(appli + ' --product ' + product_name)
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'
91 f = open(expected_file_path, 'r')
92 text = f.readlines()[0]
94 # pyunit method to compare 2 str
95 self.assertEqual(text, expected_text)
98 def test_source_svn(self):
99 '''Test the source command with svn product
104 product_name = 'PRODUCT_SVN'
107 sat.source(appli + ' --product ' + product_name)
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'
113 f = open(expected_file_path, 'r')
114 text = f.readlines()[0]
116 if expected_text in text:
119 # pyunit method to compare 2 str
120 self.assertEqual(OK, 'OK')
123 def test_source_native(self):
124 '''Test the source command with native product
129 product_name = 'PRODUCT_NATIVE'
132 sat.source(appli + ' --product ' + product_name)
134 expected_src_dir = os.path.join(sat.cfg.APPLICATION.workdir, 'SOURCES', product_name)
135 if not os.path.exists(expected_src_dir):
138 # pyunit method to compare 2 str
139 self.assertEqual(OK, 'OK')
141 def test_source_fixed(self):
142 '''Test the source command with fixed product
147 product_name = 'PRODUCT_FIXED'
150 sat.source(appli + ' --product ' + product_name)
152 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
154 if os.path.exists(expected_src_dir):
157 # pyunit method to compare 2 str
158 self.assertEqual(OK, 'OK')
160 def test_source_unknown(self):
161 '''Test the source command with unknown product
166 my_out = outRedirection()
169 product_name = 'PRODUCT_UNKNOWN'
172 sat.source(appli + ' --product ' + product_name)
174 # stop output redirection
175 my_out.end_redirection()
178 res = my_out.read_results()
180 if "Unknown get source method" in res:
183 # pyunit method to compare 2 str
184 self.assertEqual(OK, 'OK')
187 def test_description(self):
188 '''Test the sat -h source
195 if "gets the sources of the application" in source.description():
198 # pyunit method to compare 2 str
199 self.assertEqual(OK, "OK")
202 if __name__ == '__main__':
203 HTMLTestRunner.main()