Salome HOME
Add first testing procedure
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 1 Feb 2016 08:42:55 +0000 (09:42 +0100)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Mon, 1 Feb 2016 08:42:55 +0000 (09:42 +0100)
src/salomeTools.py
test/__TOOLS__/tools.py [new file with mode: 0644]
test/config/integration/option_value.py [new file with mode: 0644]
test/test.py

index 78dc0afb6a902bf05567f1ec273d8385d56b8188..b640e425976a3183cb4c2e77315326c50b0b22d1 100755 (executable)
@@ -128,14 +128,14 @@ class salomeTools(object):
                 if not self.cfg:
                     # read the configuration from all the pyconf files    
                     cfgManager = config.ConfigManager()
-                    self.cfg = cfgManager.getConfig(dataDir=self.dataDir, application=appliToLoad, options=self.options)
+                    self.cfg = cfgManager.getConfig(dataDir=self.dataDir, application=appliToLoad, options=self.options, command=__nameCmd__)
                 
                 return __module__.run(argv, self)
 
             # Make sure that run_command will be redefined at each iteration of the loop
             globals_up = {}
             globals_up.update(run_command.__globals__)
-            globals_up.update({'__name__': nameCmd, '__module__' : module})
+            globals_up.update({'__nameCmd__': nameCmd, '__module__' : module})
             func = types.FunctionType(run_command.__code__, globals_up, run_command.__name__,run_command.__defaults__, run_command.__closure__)
 
             # set the attribute corresponding to the command
diff --git a/test/__TOOLS__/tools.py b/test/__TOOLS__/tools.py
new file mode 100644 (file)
index 0000000..daf88a7
--- /dev/null
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import tempfile
+import sys
+import subprocess
+
+class outRedirection():
+    '''redirection of standart output
+    useful for testing the terminal display
+    '''
+    def __init__(self):
+        '''initialization
+        '''
+        self._fstream = tempfile.NamedTemporaryFile(mode='w')
+        self.saveout = sys.stdout
+        sys.stdout = self._fstream
+
+    def flush(self):
+        self._fstream.flush()                
+
+    def end_redirection(self):
+        self._fstream.seek(0)
+        ff = open(self._fstream.name, 'r')
+        self.res = ff.read()
+        self._fstream.close()
+        sys.stdout = self.saveout
+        
+    def read_results(self):
+        try:
+            return self.res
+        except Exception as exc:
+            print('Problem with redirection : %s' % exc)
+            sys.exit(1)
+            
+def check_proc_existence(cmd, text_to_find):
+    
+    p = subprocess.Popen(cmd, shell=True)
+    p.communicate()
\ No newline at end of file
diff --git a/test/config/integration/option_value.py b/test/config/integration/option_value.py
new file mode 100644 (file)
index 0000000..883039a
--- /dev/null
@@ -0,0 +1,59 @@
+#!/usr/bin/env python
+#-*- coding:utf-8 -*-
+#  Copyright (C) 2010-2012  CEA/DEN
+#
+#  This library is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU Lesser General Public
+#  License as published by the Free Software Foundation; either
+#  version 2.1 of the License.
+#
+#  This library is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+#  Lesser General Public License for more details.
+#
+#  You should have received a copy of the GNU Lesser General Public
+#  License along with this library; if not, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+
+import unittest
+import os
+import sys
+
+# 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', '__TOOLS__'))
+
+from salomeTools import salomeTools
+from tools import outRedirection
+
+class TestConfig(unittest.TestCase):
+    '''pyunit class : each method execute one test.
+    '''
+    
+    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'
+
+        # output redirection
+        my_out = outRedirection()
+
+        # The command to test
+        sat = salomeTools('')
+        sat.config('-v VARS.hostname')
+
+        # stop output redirection
+        my_out.end_redirection()
+
+        # get results
+        res = my_out.read_results()
+
+        # pyunit method to compare 2 str
+        self.assertEqual(res, expected)
+
+# test launch
+if __name__ == '__main__':
+    unittest.main()
\ No newline at end of file
index 842475a4641868e9181b69ee4f4340fc2324427e..5c52d4b4a7f852afdef208bf1715605f5a38bd24 100644 (file)
@@ -16,7 +16,8 @@
 #  License along with this library; if not, write to the Free Software
 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 
-import os, sys
+import os
+import sys
 
 # get execution path
 testdir = os.path.dirname(os.path.realpath(__file__))