Salome HOME
3a63fd5afd80269b92d26870b440e9a4aa14c277
[tools/sat.git] / test / test_sat5_0 / environ / test_environ.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
26 class TestSource(unittest.TestCase):
27     """Test of the environ command"""
28     
29     def test_010(self):
30         # Test the environ command without any option
31         OK = 'KO'
32         
33         appli = 'appli-test'
34
35         file_env_name = 'env_launch.sh'
36         
37         sat = Sat()
38         sat.config(appli)
39
40         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
41
42         if os.path.exists(expected_file_path):
43             os.remove(expected_file_path)
44
45         sat.environ(appli)
46
47         if os.path.exists(expected_file_path):
48             OK = 'OK'
49         self.assertEqual(OK, 'OK')
50
51     def test_020(self):
52         # Test the environ command with option '--products'
53         OK = 'KO'
54         
55         appli = 'appli-test'
56         product_name = 'PRODUCT_GIT'
57         
58         file_env_name = 'env_launch.sh'
59         
60         sat = Sat()
61         sat.config(appli)
62
63         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
64
65         if os.path.exists(expected_file_path):
66             os.remove(expected_file_path)
67
68         sat.environ(appli + ' --products ' + product_name)
69
70         if os.path.exists(expected_file_path):
71             OK = 'OK'
72         self.assertEqual(OK, 'OK')        
73
74     def test_030(self):
75         # Test the environ command with option --target
76         OK = 'KO'
77         
78         appli = 'appli-test'
79         
80         file_env_name = 'env_launch.sh'
81         
82         sat = Sat()
83         sat.config(appli)
84
85         expected_file_path = os.path.join('.', file_env_name)
86         expected_file_path2 = os.path.join('.', 'env_build.sh')
87
88         if os.path.exists(expected_file_path):
89             os.remove(expected_file_path)
90
91         sat.environ(appli + ' --target .')
92
93         if os.path.exists(expected_file_path):
94             OK = 'OK'
95
96         if os.path.exists(expected_file_path):
97             os.remove(expected_file_path)
98             os.remove(expected_file_path2)
99
100         # pyunit method to compare 2 str
101         self.assertEqual(OK, 'OK') 
102
103     def test_040(self):
104         # Test the environ command with option --prefix
105         OK = 'KO'
106         
107         appli = 'appli-test'
108         prefix = 'TEST'
109         file_env_name = prefix + '_launch.sh'
110         
111         sat = Sat()
112         sat.config(appli)
113
114         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
115
116         if os.path.exists(expected_file_path):
117             os.remove(expected_file_path)
118
119         sat.environ(appli + ' --prefix ' + prefix)
120
121         if os.path.exists(expected_file_path):
122             OK = 'OK'
123         self.assertEqual(OK, 'OK') 
124
125     def test_050(self):
126         # Test the environ command with option --shell
127         OK = 'KO'
128         
129         appli = 'appli-test'
130         shell = 'bat'
131         file_env_name = 'env_launch.bat'
132         
133         sat = Sat()
134         sat.config(appli)
135
136         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
137
138         if os.path.exists(expected_file_path):
139             os.remove(expected_file_path)
140
141         sat.environ(appli + ' --shell ' + shell)
142
143         if os.path.exists(expected_file_path):
144             OK = 'OK'
145         self.assertEqual(OK, 'OK') 
146
147 # test launch
148 if __name__ == '__main__':
149     unittest.main()
150     pass