Salome HOME
678d3f0b53e5b3fb3c6fa150bc1a2cdf53f962f6
[tools/sat.git] / test / config / option_value.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 platform
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 from tools import outRedirection
31 import HTMLTestRunner
32
33 class TestConfig(unittest.TestCase):
34     '''OPTION VALUE.
35     '''
36     
37     def test_option_value(self):
38         '''Test the display of the right value of "sat config -v VARS.hostname"
39         '''
40
41         OK = "KO"
42
43         # output redirection
44         my_out = outRedirection()
45
46         # The command to test
47         sat = Sat()
48         sat.config('-v VARS.hostname')
49
50         # stop output redirection
51         my_out.end_redirection()
52
53         # get results
54         res = my_out.read_results()
55
56         if platform.node() in res:
57             OK = "OK"
58
59         # pyunit method to compare 2 str
60         self.assertEqual(OK, "OK")
61
62     def test_option_list(self):
63         '''Test the display of the right value of "sat config -l"
64         '''
65         
66         OK = "KO"
67
68         # output redirection
69         my_out = outRedirection()
70
71         # The command to test
72         sat = Sat()
73         sat.config('-l')
74
75         # stop output redirection
76         my_out.end_redirection()
77
78         # get results
79         res = my_out.read_results()
80
81         # get results
82         if "ERROR" not in res:
83             OK = "OK"
84
85         # pyunit method to compare 2 str
86         self.assertEqual(OK, "OK")
87     
88     """    
89     def test_error_salomeToolspyconf(self):
90         '''Test the exception when salomeTools.pyconf has errors
91         '''      
92         
93         OK = "KO"
94         
95         # The command to test
96         sat = Sat()
97         sat.config()
98         
99         salomeToolspyconfPath = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf")
100         salomeToolspyconfPath_save = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf_save")
101         if os.path.exists(salomeToolspyconfPath_save):
102             os.remove(salomeToolspyconfPath_save)
103         shutil.copyfile(salomeToolspyconfPath, salomeToolspyconfPath_save)
104         f_read = open(salomeToolspyconfPath, 'r')
105         text = f_read.read()
106         f_read.close()
107         os.remove(salomeToolspyconfPath)
108         f_write = open(salomeToolspyconfPath, 'w')
109         f_write.write(text.replace(':', ''))
110         f_write.close()
111         
112         try:
113             sat.config()
114         except TypeError:
115             OK = "OK"
116         finally:
117             shutil.copyfile(salomeToolspyconfPath_save, salomeToolspyconfPath)
118             os.remove(salomeToolspyconfPath_save)
119         
120         # pyunit method to compare 2 str
121         self.assertEqual(OK, "OK")
122     """       
123         
124 # test launch
125 if __name__ == '__main__':
126     HTMLTestRunner.main()