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