Salome HOME
merge from master 8B7B
[tools/sat.git] / test / test_sat5_0 / config / test_create_user_pyconf.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 shutil
23 import unittest
24
25 from src.salomeTools import Sat
26
27 class TestCase(unittest.TestCase):
28     """Test create file .pyconf"""
29     
30     def test_010(self):
31         # Test creation of ~/.salomeTools/salomeTools.pyconf
32         print "stupidity HAVE TO NOT touch user ~/.salomeTools"
33         return
34         
35         res = "KO"
36         user_dir = os.path.expanduser(os.path.join('~','.salomeTools'))
37         user_dir_save = os.path.expanduser(os.path.join('~','.salomeTools_save'))
38         if os.path.exists(user_dir_save):
39             shutil.rmtree(user_dir_save)
40         if os.path.exists(user_dir):
41             shutil.move(user_dir, user_dir_save)
42                
43         # The command to test
44         sat = Sat('')
45         sat.config('-v .')
46
47         expected_file = os.path.expanduser(os.path.join('~','.salomeTools', 'salomeTools.pyconf'))
48
49         if os.path.exists(expected_file):
50             res = "OK"
51
52         shutil.rmtree(user_dir)
53         shutil.move(user_dir_save, user_dir)
54         self.assertEqual(res, "OK")
55
56     def test_020(self):
57         # Test override VARS
58         OK = "KO"
59         
60         # The command to test
61         sat = Sat("-oVARS.user='user_test'")
62         sat.config()
63
64         if sat.cfg.VARS.user == 'user_test':
65             OK = "OK"
66         self.assertEqual(OK, "OK")
67
68     def test_030(self):
69         # Test override INTERNAL
70         OK = "KO"
71         
72         # The command to test
73         sat = Sat("-oINTERNAL.sat_version='V0'")
74         sat.config()
75
76         if sat.cfg.INTERNAL.sat_version == 'V0':
77             OK = "OK"
78         self.assertEqual(OK, "OK")
79
80     """
81     def test_040(self):
82         # Test override SITE
83         OK = "KO"
84         
85         # The command to test
86         sat = Sat("-oSITE.jobs.config_path='/tmp'")
87         sat.config()
88
89         if sat.cfg.SITE.jobs.config_path == '/tmp':
90             OK = "OK"
91
92         self.assertEqual(OK, "OK")
93     """
94
95     def test_050(self):
96         # Test override APPLICATION
97         OK = "KO"
98         
99         # The command to test
100         sat = Sat("-oAPPLICATION.out_dir='/tmp'")
101         sat.config('appli-test')
102
103         if sat.cfg.APPLICATION.out_dir == '/tmp':
104             OK = "OK"
105         self.assertEqual(OK, "OK")
106
107     def test_060(self):
108         # Test override PRODUCTS
109         OK = "KO"
110         
111         # The command to test
112         sat = Sat("-oPRODUCTS.PRODUCT_GIT.default.name='test'")
113         sat.config('')
114
115         if sat.cfg.PRODUCTS.PRODUCT_GIT.default.name == 'test':
116             OK = "OK"
117         self.assertEqual(OK, "OK")
118
119 # test launch
120 if __name__ == '__main__':
121     unittest.main()
122     pass