Salome HOME
Merge branch 'BR_8_3' of https://codev-tuleap.cea.fr/plugins/git/spns/SAT into BR_8_3
[tools/sat.git] / test / config / option_value.py
index 2b1d90384aad2fb063a996f3479abf69b15e7abd..678d3f0b53e5b3fb3c6fa150bc1a2cdf53f962f6 100644 (file)
 import unittest
 import os
 import sys
+import platform
 
 # get execution path
 testdir = os.path.dirname(os.path.realpath(__file__))
-sys.path.append(os.path.join(testdir, '..', '..', 'src'))
-sys.path.append(os.path.join(testdir, '..', '..', 'test', '_testTools'))
+sys.path.append(os.path.join(testdir, '..', '..'))
+sys.path.append(os.path.join(testdir, '..', '_testTools'))
 
-from salomeTools import salomeTools
+from salomeTools import Sat
 from tools import outRedirection
 import HTMLTestRunner
 
 class TestConfig(unittest.TestCase):
-    '''pyunit class : each method execute one test.
+    '''OPTION VALUE.
     '''
     
     def test_option_value(self):
         '''Test the display of the right value of "sat config -v VARS.hostname"
         '''
-        # expected value
-        expected = '\x1b[36mhostname\x1b[0m: is221560\n'
+
+        OK = "KO"
 
         # output redirection
         my_out = outRedirection()
 
         # The command to test
-        sat = salomeTools('')
+        sat = Sat()
         sat.config('-v VARS.hostname')
 
         # stop output redirection
@@ -52,20 +53,23 @@ class TestConfig(unittest.TestCase):
         # get results
         res = my_out.read_results()
 
+        if platform.node() in res:
+            OK = "OK"
+
         # pyunit method to compare 2 str
-        self.assertEqual(res, expected)
+        self.assertEqual(OK, "OK")
 
     def test_option_list(self):
         '''Test the display of the right value of "sat config -l"
         '''
-        # expected value
-        expected = '------ \x1b[34m/home/salome/SPN_PRIVATE/sat5dev_Applications\x1b[0m\nappli-test\n\n------ \x1b[34m/export/home/serioja/.salomeTools/Applications\x1b[0m\n\n'
+        
+        OK = "KO"
 
         # output redirection
         my_out = outRedirection()
 
         # The command to test
-        sat = salomeTools('')
+        sat = Sat()
         sat.config('-l')
 
         # stop output redirection
@@ -74,9 +78,49 @@ class TestConfig(unittest.TestCase):
         # get results
         res = my_out.read_results()
 
-        # pyunit method to compare 2 str
-        self.assertEqual(res, expected)
+        # get results
+        if "ERROR" not in res:
+            OK = "OK"
 
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+    
+    """    
+    def test_error_salomeToolspyconf(self):
+        '''Test the exception when salomeTools.pyconf has errors
+        '''      
+        
+        OK = "KO"
+        
+        # The command to test
+        sat = Sat()
+        sat.config()
+        
+        salomeToolspyconfPath = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf")
+        salomeToolspyconfPath_save = os.path.join(sat.cfg.VARS.srcDir, "internal_config", "salomeTools.pyconf_save")
+        if os.path.exists(salomeToolspyconfPath_save):
+            os.remove(salomeToolspyconfPath_save)
+        shutil.copyfile(salomeToolspyconfPath, salomeToolspyconfPath_save)
+        f_read = open(salomeToolspyconfPath, 'r')
+        text = f_read.read()
+        f_read.close()
+        os.remove(salomeToolspyconfPath)
+        f_write = open(salomeToolspyconfPath, 'w')
+        f_write.write(text.replace(':', ''))
+        f_write.close()
+        
+        try:
+            sat.config()
+        except TypeError:
+            OK = "OK"
+        finally:
+            shutil.copyfile(salomeToolspyconfPath_save, salomeToolspyconfPath)
+            os.remove(salomeToolspyconfPath_save)
+        
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, "OK")
+    """       
+        
 # test launch
 if __name__ == '__main__':
     HTMLTestRunner.main()