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