]> SALOME platform Git repositories - tools/sat.git/commitdiff
Salome HOME
add test for environ sprint-04
authorSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 27 Apr 2016 14:44:53 +0000 (16:44 +0200)
committerSerge Rehbinder <serge.rehbinder@cea.fr>
Wed, 27 Apr 2016 14:44:53 +0000 (16:44 +0200)
commands/environ.py
src/options.py
test/environ/test_environ.py [new file with mode: 0644]
test/run_all.sh

index 3c1a939a31af589b833e1cab1ff7cf3c4ac9fb64..f34396d6b5a03ad0f4ae13570f788baa7fa279f3 100644 (file)
@@ -25,7 +25,7 @@ parser.add_option('', 'shell', 'list2', 'shell',
     _("Generates the environment files for the given format: bash (default), batch or all."), [])
 parser.add_option('p', 'products', 'list2', 'products',
     _("Includes only the specified products."))
-parser.add_option('p', 'prefix', 'string', 'prefix',
+parser.add_option('', 'prefix', 'string', 'prefix',
     _("Specifies the prefix for the environment files."), "env")
 parser.add_option('t', 'target', 'string', 'out_dir',
     _("Specifies the directory path where to put the environment files."), None)
@@ -39,6 +39,7 @@ C_ALL_SHELL = [ "bash", "batch" ]
 # Writes all the environment files
 def write_all_source_files(config, logger, out_dir=None, src_root=None,
                            silent=False, shells=["bash"], prefix="env", env_info=None):
+    
     if not out_dir:
         out_dir = config.APPLICATION.workdir
 
@@ -89,7 +90,7 @@ def run(args, runner, logger):
 
     # check that the command was called with an application
     src.check_config_has_application( runner.cfg )
-   
+    
     if options.products is None:
         environ_info = None
     else:
@@ -103,6 +104,10 @@ def run(args, runner, logger):
     else:
         shell = options.shell
     
-    write_all_source_files(runner.cfg, logger, out_dir=options.out_dir, shells=shell,
+    out_dir = options.out_dir
+    if out_dir:
+        out_dir = os.path.abspath(out_dir)
+    
+    write_all_source_files(runner.cfg, logger, out_dir=out_dir, shells=shell,
                            prefix=options.prefix, env_info=environ_info)
     logger.write("\n", 3, False)
index 79f059ee38b3aee8ff3232b9aed6efe53f0dbe4b..2cfeae0ae84246bbe33a8ffa966b5db2fbe801b3 100644 (file)
@@ -72,6 +72,7 @@ class Options:
         # The list of available option type
         self.availableOptions = ["boolean", "string", "int", "float",
                                   "long", "list", "list2"]
+        self.default = None
 
     def add_option(self, shortName, longName,
                     optionType, destName, helpString="", default = None):
diff --git a/test/environ/test_environ.py b/test/environ/test_environ.py
new file mode 100644 (file)
index 0000000..7677017
--- /dev/null
@@ -0,0 +1,169 @@
+#!/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, '..', '..'))
+sys.path.append(os.path.join(testdir, '..', '_testTools'))
+sys.path.append(os.path.join(testdir, '..', '..','commands'))
+
+from salomeTools import Sat
+import HTMLTestRunner
+
+class TestSource(unittest.TestCase):
+    '''Test of the source command
+    '''
+    
+    def test_environ_no_option(self):
+        '''Test the environ command without any option
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+
+        file_env_name = 'env_launch.sh'
+        
+        sat = Sat()
+        sat.config(appli)
+
+        expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+
+        sat.environ(appli)
+
+        if os.path.exists(expected_file_path):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')
+
+    def test_environ_option_products(self):
+        '''Test the environ command with option --products
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        product_name = 'PRODUCT_GIT'
+        
+        file_env_name = 'env_launch.sh'
+        
+        sat = Sat()
+        sat.config(appli)
+
+        expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+
+        sat.environ(appli + ' --products ' + product_name)
+
+        if os.path.exists(expected_file_path):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK')        
+
+    def test_environ_option_target(self):
+        '''Test the environ command with option --target
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        
+        file_env_name = 'env_launch.sh'
+        
+        sat = Sat()
+        sat.config(appli)
+
+        expected_file_path = os.path.join('.', file_env_name)
+        expected_file_path2 = os.path.join('.', 'env_build.sh')
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+
+        sat.environ(appli + ' --target .')
+
+        if os.path.exists(expected_file_path):
+            OK = 'OK'
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+            os.remove(expected_file_path2)
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK') 
+
+    def test_environ_option_prefix(self):
+        '''Test the environ command with option --prefix
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        prefix = 'TEST'
+        file_env_name = prefix + '_launch.sh'
+        
+        sat = Sat()
+        sat.config(appli)
+
+        expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+
+        sat.environ(appli + ' --prefix ' + prefix)
+
+        if os.path.exists(expected_file_path):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK') 
+
+    def test_environ_option_shell(self):
+        '''Test the environ command with option --shell
+        '''
+        OK = 'KO'
+        
+        appli = 'appli-test'
+        shell = 'batch'
+        file_env_name = 'env_launch.bat'
+        
+        sat = Sat()
+        sat.config(appli)
+
+        expected_file_path = os.path.join(sat.cfg.APPLICATION.workdir, file_env_name)
+
+        if os.path.exists(expected_file_path):
+            os.remove(expected_file_path)
+
+        sat.environ(appli + ' --shell ' + shell)
+
+        if os.path.exists(expected_file_path):
+            OK = 'OK'
+
+        # pyunit method to compare 2 str
+        self.assertEqual(OK, 'OK') 
+
+# test launch
+if __name__ == '__main__':
+    HTMLTestRunner.main()
index bec400b6124024eab27bc528e30d54962d3eb39d..38b003a857f3cd24c577dc23c9575de91cfb87d2 100755 (executable)
@@ -28,6 +28,7 @@ coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager
 coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_source.py >> test_res.html
 coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_patch.py >> test_res.html
 coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../src/product.py -a prepare/test_prepare.py >> test_res.html
+coverage run --source=../commands/config.py,../commands/environ.py,../src/environment.py,../src/fileEnviron.py -a environ/test_environ.py >> test_res.html
 coverage html
 
-#firefox test_res.html htmlcov/index.html
+#firefox test_res.html htmlcov/index.html
\ No newline at end of file