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
24 from src.salomeTools import Sat
26 from unittestpy.tools import outRedirection
28 class TestCase(unittest.TestCase):
29 """Test of the source command"""
32 # Test the source command with archive product
34 product_name = 'PRODUCT_ARCHIVE'
37 sat.source(appli + ' --product ' + product_name)
39 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
40 expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
41 expected_text = 'HELLO WORLD\n'
43 f = open(expected_file_path, 'r')
45 self.assertEqual(text, expected_text)
48 # Test the source command with git product
50 product_name = 'PRODUCT_GIT'
53 sat.source(appli + ' --product ' + product_name)
55 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
56 expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt')
57 expected_text = 'HELLO WORLD\n'
59 f = open(expected_file_path, 'r')
61 self.assertEqual(text, expected_text)
64 # Test the source command with cvs product
66 product_name = 'PRODUCT_CVS'
69 sat.source(appli + ' --product ' + product_name)
71 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
72 expected_file_path = os.path.join(expected_src_dir, 'README.FIRST.txt')
73 expected_text = 'Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE\n'
75 f = open(expected_file_path, 'r')
76 text = f.readlines()[0]
78 # pyunit method to compare 2 str
79 self.assertEqual(text, expected_text)
83 # Test the source command with svn product
87 product_name = 'PRODUCT_SVN'
90 sat.source(appli + ' --product ' + product_name)
92 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir
93 expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README')
94 expected_text = 'this directory contains scripts used by salomeTool'
96 f = open(expected_file_path, 'r')
97 text = f.readlines()[0]
99 if expected_text in text:
102 # pyunit method to compare 2 str
103 self.assertEqual(OK, 'OK')
107 # Test the source command with native product
111 product_name = 'PRODUCT_NATIVE'
114 sat.source(appli + ' --product ' + product_name)
116 expected_src_dir = os.path.join(sat.cfg.APPLICATION.workdir, 'SOURCES', product_name)
117 if not os.path.exists(expected_src_dir):
119 self.assertEqual(OK, 'OK')
122 # Test the source command with fixed product
126 product_name = 'PRODUCT_FIXED'
129 sat.source(appli + ' --product ' + product_name)
131 expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
133 if os.path.exists(expected_src_dir):
135 self.assertEqual(OK, 'OK')
139 # Test the source command with unknown product
143 my_out = outRedirection()
146 product_name = 'PRODUCT_UNKNOWN'
149 sat.source(appli + ' --product ' + product_name)
151 # stop output redirection
152 my_out.end_redirection()
155 res = my_out.read_results()
157 if "Unknown get source method" in res:
159 self.assertEqual(OK, 'OK')
163 # Test the sat -h source
168 if "gets the sources of the application" in source.description():
170 self.assertEqual(OK, "OK")
173 if __name__ == '__main__':