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
--- /dev/null
+#!/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
--- /dev/null
+#!/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
# 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__))