Salome HOME
Add tests for clean command
[tools/sat.git] / test / environ / test_environ.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3 #  Copyright (C) 2010-2012  CEA/DEN
4 #
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.
9 #
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.
14 #
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
18
19 import unittest
20 import os
21 import sys
22
23 # get execution path
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'))
28
29 from salomeTools import Sat
30 import HTMLTestRunner
31
32 class TestSource(unittest.TestCase):
33     '''Test of the source command
34     '''
35     
36     def test_environ_no_option(self):
37         '''Test the environ command without any option
38         '''
39         OK = 'KO'
40         
41         appli = 'appli-test'
42
43         file_env_name = 'env_launch.sh'
44         
45         sat = Sat()
46         sat.config(appli)
47
48         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
49
50         if os.path.exists(expected_file_path):
51             os.remove(expected_file_path)
52
53         sat.environ(appli)
54
55         if os.path.exists(expected_file_path):
56             OK = 'OK'
57
58         # pyunit method to compare 2 str
59         self.assertEqual(OK, 'OK')
60
61     def test_environ_option_products(self):
62         '''Test the environ command with option --products
63         '''
64         OK = 'KO'
65         
66         appli = 'appli-test'
67         product_name = 'PRODUCT_GIT'
68         
69         file_env_name = 'env_launch.sh'
70         
71         sat = Sat()
72         sat.config(appli)
73
74         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
75
76         if os.path.exists(expected_file_path):
77             os.remove(expected_file_path)
78
79         sat.environ(appli + ' --products ' + product_name)
80
81         if os.path.exists(expected_file_path):
82             OK = 'OK'
83
84         # pyunit method to compare 2 str
85         self.assertEqual(OK, 'OK')        
86
87     def test_environ_option_target(self):
88         '''Test the environ command with option --target
89         '''
90         OK = 'KO'
91         
92         appli = 'appli-test'
93         
94         file_env_name = 'env_launch.sh'
95         
96         sat = Sat()
97         sat.config(appli)
98
99         expected_file_path = os.path.join('.', file_env_name)
100         expected_file_path2 = os.path.join('.', 'env_build.sh')
101
102         if os.path.exists(expected_file_path):
103             os.remove(expected_file_path)
104
105         sat.environ(appli + ' --target .')
106
107         if os.path.exists(expected_file_path):
108             OK = 'OK'
109
110         if os.path.exists(expected_file_path):
111             os.remove(expected_file_path)
112             os.remove(expected_file_path2)
113
114         # pyunit method to compare 2 str
115         self.assertEqual(OK, 'OK') 
116
117     def test_environ_option_prefix(self):
118         '''Test the environ command with option --prefix
119         '''
120         OK = 'KO'
121         
122         appli = 'appli-test'
123         prefix = 'TEST'
124         file_env_name = prefix + '_launch.sh'
125         
126         sat = Sat()
127         sat.config(appli)
128
129         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
130
131         if os.path.exists(expected_file_path):
132             os.remove(expected_file_path)
133
134         sat.environ(appli + ' --prefix ' + prefix)
135
136         if os.path.exists(expected_file_path):
137             OK = 'OK'
138
139         # pyunit method to compare 2 str
140         self.assertEqual(OK, 'OK') 
141
142     def test_environ_option_shell(self):
143         '''Test the environ command with option --shell
144         '''
145         OK = 'KO'
146         
147         appli = 'appli-test'
148         shell = 'bat'
149         file_env_name = 'env_launch.bat'
150         
151         sat = Sat()
152         sat.config(appli)
153
154         expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
155
156         if os.path.exists(expected_file_path):
157             os.remove(expected_file_path)
158
159         sat.environ(appli + ' --shell ' + shell)
160
161         if os.path.exists(expected_file_path):
162             OK = 'OK'
163
164         # pyunit method to compare 2 str
165         self.assertEqual(OK, 'OK') 
166
167 # test launch
168 if __name__ == '__main__':
169     HTMLTestRunner.main()