From: Serge Rehbinder Date: Wed, 27 Apr 2016 14:44:53 +0000 (+0200) Subject: add test for environ X-Git-Tag: sprint-04 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b0a4bb0045812c4bf0143a89f32b6dc227037dc1;p=tools%2Fsat.git add test for environ --- diff --git a/commands/environ.py b/commands/environ.py index 3c1a939..f34396d 100644 --- a/commands/environ.py +++ b/commands/environ.py @@ -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) diff --git a/src/options.py b/src/options.py index 79f059e..2cfeae0 100644 --- a/src/options.py +++ b/src/options.py @@ -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 index 0000000..7677017 --- /dev/null +++ b/test/environ/test_environ.py @@ -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() diff --git a/test/run_all.sh b/test/run_all.sh index bec400b..38b003a 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -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