Salome HOME
suppresion d'un log
[tools/sat.git] / test / config / create_user_pyconf.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 import shutil
23
24 # get execution path
25 testdir = os.path.dirname(os.path.realpath(__file__))
26 sys.path.append(os.path.join(testdir, '..', '..'))
27 sys.path.append(os.path.join(testdir, '..', '_testTools'))
28
29 from salomeTools import Sat
30 import HTMLTestRunner
31
32 class TestConfig(unittest.TestCase):
33     '''pyunit class : each method execute one test.
34     '''
35     
36     def test_user_dir_creation(self):
37         '''Creation of ~/.salomeTools/salomeTools.pyconf
38         '''
39         res = "KO"
40         user_dir = os.path.expanduser(os.path.join('~','.salomeTools'))
41         user_dir_save = os.path.expanduser(os.path.join('~','.salomeTools_save'))
42         if os.path.exists(user_dir_save):
43             shutil.rmtree(user_dir_save)
44         if os.path.exists(user_dir):
45             shutil.move(user_dir, user_dir_save)
46                
47         # The command to test
48         sat = Sat('')
49         sat.config('-v .')
50
51         expected_file = os.path.expanduser(os.path.join('~','.salomeTools', 'salomeTools.pyconf'))
52
53         if os.path.exists(expected_file):
54             res = "OK"
55
56         shutil.rmtree(user_dir)
57         shutil.move(user_dir_save, user_dir)
58
59         # pyunit method to compare 2 str
60         self.assertEqual(res, "OK")
61
62     def test_override_VARS(self):
63         '''override VARS
64         '''
65         OK = "KO"
66         
67         # The command to test
68         sat = Sat("-oVARS.user='user_test'")
69         sat.config()
70
71         if sat.cfg.VARS.user == 'user_test':
72             OK = "OK"
73
74         # pyunit method to compare 2 str
75         self.assertEqual(OK, "OK")
76
77     def test_override_INTERNAL(self):
78         '''override INTERNAL
79         '''
80         OK = "KO"
81         
82         # The command to test
83         sat = Sat("-oINTERNAL.sat_version='V0'")
84         sat.config()
85
86         if sat.cfg.INTERNAL.sat_version == 'V0':
87             OK = "OK"
88
89         # pyunit method to compare 2 str
90         self.assertEqual(OK, "OK")
91
92     """
93     def test_override_SITE(self):
94         '''override SITE
95         '''
96         OK = "KO"
97         
98         # The command to test
99         sat = Sat("-oSITE.jobs.config_path='/tmp'")
100         sat.config()
101
102         if sat.cfg.SITE.jobs.config_path == '/tmp':
103             OK = "OK"
104
105         # pyunit method to compare 2 str
106         self.assertEqual(OK, "OK")
107     """
108
109     def test_override_APPLICATION(self):
110         '''override APPLICATION
111         '''
112         OK = "KO"
113         
114         # The command to test
115         sat = Sat("-oAPPLICATION.out_dir='/tmp'")
116         sat.config('appli-test')
117
118         if sat.cfg.APPLICATION.out_dir == '/tmp':
119             OK = "OK"
120
121         # pyunit method to compare 2 str
122         self.assertEqual(OK, "OK")
123
124     def test_override_PRODUCTS(self):
125         '''override PRODUCTS
126         '''
127         OK = "KO"
128         
129         # The command to test
130         sat = Sat("-oPRODUCTS.PRODUCT_GIT.default.name='test'")
131         sat.config('')
132
133         if sat.cfg.PRODUCTS.PRODUCT_GIT.default.name == 'test':
134             OK = "OK"
135
136         # pyunit method to compare 2 str
137         self.assertEqual(OK, "OK")
138
139 # test launch
140 if __name__ == '__main__':
141     HTMLTestRunner.main()