Salome HOME
spns #42205 [SAT][Windows] support different values for CMAKE_BUILD_TYPE - define...
[tools/sat.git] / test / test_sat5_0 / prepare / test_source.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 #  Copyright (C) 2010-2018  CEA/DEN
5 #
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.
10 #
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.
15 #
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
19
20 import os
21 import sys
22 import unittest
23
24 from src.salomeTools import Sat
25 import src.product
26 from unittestpy.tools import outRedirection
27
28 class TestCase(unittest.TestCase):
29     """Test of the source command"""
30     
31     def test_010(self):
32         # Test the source command with archive product
33         appli = 'appli-test'
34         product_name = 'PRODUCT_ARCHIVE'
35
36         sat = Sat()
37         sat.source(appli + ' --product ' + product_name)
38
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'
42
43         f = open(expected_file_path, 'r')
44         text = f.read()
45         self.assertEqual(text, expected_text)
46         
47     def test_020(self):
48         # Test the source command with git product
49         appli = 'appli-test'
50         product_name = 'PRODUCT_GIT'
51
52         sat = Sat()
53         sat.source(appli + ' --product ' + product_name)
54
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'
58
59         f = open(expected_file_path, 'r')
60         text = f.read()
61         self.assertEqual(text, expected_text)
62
63     def test_030(self):
64         # Test the source command with cvs product
65         appli = 'appli-test'
66         product_name = 'PRODUCT_CVS'
67
68         sat = Sat()
69         sat.source(appli + ' --product ' + product_name)
70
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'
74
75         f = open(expected_file_path, 'r')
76         text = f.readlines()[0]
77
78         # pyunit method to compare 2 str
79         self.assertEqual(text, expected_text)
80     
81     """
82     def test_040(self):
83         # Test the source command with svn product
84         OK = 'KO'
85         
86         appli = 'appli-test'
87         product_name = 'PRODUCT_SVN'
88
89         sat = Sat()
90         sat.source(appli + ' --product ' + product_name)
91
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'
95
96         f = open(expected_file_path, 'r')
97         text = f.readlines()[0]
98         
99         if expected_text in text:
100             OK = 'OK'
101          
102         # pyunit method to compare 2 str
103         self.assertEqual(OK, 'OK')
104     """
105
106     def test_050(self):
107         # Test the source command with native product
108         OK = 'KO'
109         
110         appli = 'appli-test'
111         product_name = 'PRODUCT_NATIVE'
112
113         sat = Sat()
114         sat.source(appli + ' --product ' + product_name)
115
116         expected_src_dir = os.path.join(sat.cfg.APPLICATION.workdir, 'SOURCES', product_name)
117         if not os.path.exists(expected_src_dir):
118             OK = 'OK'
119         self.assertEqual(OK, 'OK')
120
121     def test_060(self):
122         # Test the source command with fixed product
123         OK = 'KO'
124         
125         appli = 'appli-test'
126         product_name = 'PRODUCT_FIXED'
127
128         sat = Sat()
129         sat.source(appli + ' --product ' + product_name)
130
131         expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir
132
133         if os.path.exists(expected_src_dir):
134             OK = 'OK'
135         self.assertEqual(OK, 'OK')
136
137     """
138     def test_070(self):
139         # Test the source command with unknown product
140         OK = 'KO'
141
142         # output redirection
143         my_out = outRedirection()
144
145         appli = 'appli-test'
146         product_name = 'PRODUCT_UNKNOWN'
147
148         sat = Sat()
149         sat.source(appli + ' --product ' + product_name)
150
151         # stop output redirection
152         my_out.end_redirection()
153
154         # get results
155         res = my_out.read_results()
156
157         if "Unknown get source method" in res:
158             OK = 'OK'
159         self.assertEqual(OK, 'OK')
160     """
161
162     def test_080(self):
163         # Test the sat -h source
164         OK = "KO"
165
166         import source
167         
168         if "gets the sources of the application" in source.description():
169             OK = "OK"
170         self.assertEqual(OK, "OK")
171
172 # test launch
173 if __name__ == '__main__':
174     unittest.main()
175     pass