From f8c9ef7481b95fae7201ca270378e9b3605419cf Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Fri, 18 Mar 2016 10:19:28 +0100 Subject: [PATCH] Improve test procedure for source, patch and prepare commands --- commands/prepare.py | 27 +-- commands/source.py | 14 +- complete_sat.sh | 2 +- data/products/PRODUCT_ARCHIVE.pyconf | 35 +++- data/products/PRODUCT_CVS.pyconf | 2 +- data/products/PRODUCT_DEV.pyconf | 24 +++ data/products/PRODUCT_FIXED.pyconf | 4 +- data/products/PRODUCT_GIT.pyconf | 24 +++ data/products/PRODUCT_SVN.pyconf | 4 +- data/products/PRODUCT_UNKNOWN.pyconf | 18 ++ src/product.py | 7 +- test/_testTools/tools.py | 14 +- test/config/option_value_2.py | 25 +++ test/log/launch_browser.py | 32 +--- test/log/launch_browser2.py | 63 +++++++ test/prepare/test_patch.py | 191 +++++++++++++++++++ test/prepare/test_prepare.py | 95 ++++++++-- test/prepare/test_source.py | 266 +++++++++++++++++++++++++++ test/run_all.sh | 7 + 19 files changed, 781 insertions(+), 73 deletions(-) create mode 100644 data/products/PRODUCT_DEV.pyconf create mode 100644 data/products/PRODUCT_GIT.pyconf create mode 100644 data/products/PRODUCT_UNKNOWN.pyconf create mode 100644 test/log/launch_browser2.py create mode 100644 test/prepare/test_patch.py create mode 100644 test/prepare/test_source.py diff --git a/commands/prepare.py b/commands/prepare.py index f46d4b0..ece313e 100644 --- a/commands/prepare.py +++ b/commands/prepare.py @@ -27,6 +27,8 @@ parser.add_option('', 'no_sample', 'boolean', 'no_sample', _("do not prepare sample products.")) parser.add_option('f', 'force', 'boolean', 'force', _("force to prepare the products in development mode.")) +parser.add_option('f', 'force_patch', 'boolean', 'force_patch', + _("force to apply patch to the products in development mode.")) def get_products_list(options, cfg, logger): '''method that gives the product list with their informations from @@ -83,8 +85,8 @@ def description(): :return: The text to display for the prepare command description. :rtype: str ''' - return _("The prepare command apply the patches on the sources of " - "the application products if there is any") + return _("The prepare command gets the sources of " + "the application products and apply the patches if there is any.") def run(args, runner, logger): '''method that is called when salomeTools is called with prepare parameter. @@ -112,9 +114,6 @@ def run(args, runner, logger): for p_name, __ in products_infos: args_product_opt += ',' + p_name - if args_product_opt == '--product ': - args_product_opt = '' - args_sample = '' if options.no_sample: args_sample = ' --no_sample' @@ -139,12 +138,12 @@ def run(args, runner, logger): # Construct the option to pass to the patch command ldev_products = [p for p in products_infos if src.product.product_is_dev(p[1])] - if len(ldev_products) > 0: + if len(ldev_products) > 0 and not options.force_patch: msg = _("Ignoring the following products " "in development mode\n") logger.write(src.printcolors.printcWarning(msg), 1) for i, (product_name, __) in enumerate(ldev_products): - args_product_opt.replace(',' + product_name, '') + args_product_opt = args_product_opt.replace(',' + product_name, '') end_text = ', ' if i+1 == len(ldev_products): end_text = '\n' @@ -154,10 +153,14 @@ def run(args, runner, logger): msg = _("Use the --force_patch option to apply the patches anyway\n\n") logger.write(src.printcolors.printcWarning(msg), 1) - - args_patch = args_appli + args_product_opt + args_sample - - # Call the source command that gets the source - res_patch = runner.patch(args_patch) + if args_product_opt == '--product ': + msg = _("Nothing to patch\n") + logger.write(msg) + res_patch = 0 + else: + args_patch = args_appli + args_product_opt + args_sample + + # Call the source command that gets the source + res_patch = runner.patch(args_patch) return res_source + res_patch \ No newline at end of file diff --git a/commands/source.py b/commands/source.py index 5e58afa..70d7564 100644 --- a/commands/source.py +++ b/commands/source.py @@ -51,6 +51,11 @@ def get_source_for_dev(config, product_info, source_dir, force, logger, pad): # get it in checkout mode, else, do not do anything # unless the force option is invoked if not os.path.exists(product_info.source_dir) or force: + # If the source path exists (it means that force option is invoked) + # remove the source path + if source_dir.exists(): + source_dir.rm() + # Call the function corresponding to get the sources with True checkout retcode = get_product_sources(config, product_info, @@ -303,14 +308,9 @@ def get_product_sources(config, # skip logger.write('%s ...' % _("fixed (ignored)"), 3, False) return True - - if len(product_info.get_source) == 0: - # skip - logger.write('%s ...' % _("ignored"), 3, False) - return True - # if the get_source is not in [git, archive, cvs, svn, dir] - logger.write(_("Unknown get_mehtod %(get)s for product %(product)s") % \ + # if the get_source is not in [git, archive, cvs, svn, fixed, native] + logger.write(_("Unknown get source method \"%(get)s\" for product %(product)s") % \ { 'get': product_info.get_source, 'product': product_info.name }, 3, False) logger.write(" ... ", 3, False) logger.flush() diff --git a/complete_sat.sh b/complete_sat.sh index b768555..ac6f8e0 100755 --- a/complete_sat.sh +++ b/complete_sat.sh @@ -150,7 +150,7 @@ _salomeTools_complete() return 0 ;; prepare) - opts="--product --no_sample --force" + opts="--product --no_sample --force --force_patch" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; diff --git a/data/products/PRODUCT_ARCHIVE.pyconf b/data/products/PRODUCT_ARCHIVE.pyconf index 64a9a14..04250d8 100644 --- a/data/products/PRODUCT_ARCHIVE.pyconf +++ b/data/products/PRODUCT_ARCHIVE.pyconf @@ -1,16 +1,35 @@ -MODULE_ARCHIVE : +PRODUCT_ARCHIVE : { - name : "MODULE_ARCHIVE" + name : "PRODUCT_ARCHIVE" build_source : "cmake" - get_source : "archive" - git_info: + get_source : "native" + archive_info: + { + archive_name : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product-4.4.2.tar.gz' + } + environ : { - repo : "http://git.salome-platform.org/gitpub/modules/kernel.git" - repo_dev : $SITE.prepare.default_git_server_dev + $VARS.sep + $name + "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"] } + depend : [] + opt_depend : [] + type : "sample" + source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name + build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name + patches : ['/home/salome/salomeTools-4.3.7/data/compil_scripts/patches/scipy.patch', '/export/home/serioja/MODULE_ARCHIVE.patch'] +} + +PRODUCT_ARCHIVE_4_4_2 : +{ + name : "PRODUCT_ARCHIVE" + build_source : "cmake" + get_source : "archive" archive_info: { - archive_name : '/data/tmpsalome/salome/prerequis/archives/tclx8.4.tar.bz2' + archive_name : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product-4.4.2.tar.gz' } environ : { @@ -24,5 +43,5 @@ MODULE_ARCHIVE : type : "sample" source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name - patches : ['/home/salome/salomeTools-4.3.7/data/compil_scripts/patches/scipy.patch', '/export/home/serioja/MODULE_ARCHIVE.patch'] + patches : [] } \ No newline at end of file diff --git a/data/products/PRODUCT_CVS.pyconf b/data/products/PRODUCT_CVS.pyconf index 17e956f..a7f6e12 100644 --- a/data/products/PRODUCT_CVS.pyconf +++ b/data/products/PRODUCT_CVS.pyconf @@ -1,4 +1,4 @@ -MODULE_CVS_V6_7_0 : +PRODUCT_CVS_V6_7_0 : { name : "MODULE_CVS" build_source : "cmake" diff --git a/data/products/PRODUCT_DEV.pyconf b/data/products/PRODUCT_DEV.pyconf new file mode 100644 index 0000000..7666c90 --- /dev/null +++ b/data/products/PRODUCT_DEV.pyconf @@ -0,0 +1,24 @@ +PRODUCT_DEV : +{ + name : "PRODUCT_DEV" + build_source : "cmake" + get_source : "git" + git_info: + { + repo : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product.git' + repo_dev : $repo + } + environ : + { + "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"] + } + depend : [] + opt_depend : [] + type : "sample" + source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name + build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name + patches : [$VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'mypatch.patch'] +} \ No newline at end of file diff --git a/data/products/PRODUCT_FIXED.pyconf b/data/products/PRODUCT_FIXED.pyconf index 362fea2..4bfc5ac 100644 --- a/data/products/PRODUCT_FIXED.pyconf +++ b/data/products/PRODUCT_FIXED.pyconf @@ -1,6 +1,6 @@ -MODULE_FIXED : +PRODUCT_FIXED : { - name : "MODULE_FIXED" + name : "PRODUCT_FIXED" get_source : "fixed" environ : { diff --git a/data/products/PRODUCT_GIT.pyconf b/data/products/PRODUCT_GIT.pyconf new file mode 100644 index 0000000..e611198 --- /dev/null +++ b/data/products/PRODUCT_GIT.pyconf @@ -0,0 +1,24 @@ +PRODUCT_GIT : +{ + name : "PRODUCT_GIT" + build_source : "cmake" + get_source : "git" + git_info: + { + repo : $VARS.salometoolsway + $VARS.sep + '..' + $VARS.sep + 'RESOURCES' + $VARS.sep + 'test-product.git' + repo_dev : $repo + } + environ : + { + "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"] + } + depend : [] + opt_depend : [] + type : "sample" + source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name + build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name + patches : [] +} \ No newline at end of file diff --git a/data/products/PRODUCT_SVN.pyconf b/data/products/PRODUCT_SVN.pyconf index 4856e99..9a657b9 100644 --- a/data/products/PRODUCT_SVN.pyconf +++ b/data/products/PRODUCT_SVN.pyconf @@ -1,6 +1,6 @@ -MODULE_SVN : +PRODUCT_SVN : { - name : "MODULE_SVN" + name : "PRODUCT_SVN" build_source : "cmake" get_source : "svn" git_info: diff --git a/data/products/PRODUCT_UNKNOWN.pyconf b/data/products/PRODUCT_UNKNOWN.pyconf new file mode 100644 index 0000000..6821d4b --- /dev/null +++ b/data/products/PRODUCT_UNKNOWN.pyconf @@ -0,0 +1,18 @@ +PRODUCT_UNKNOWN : +{ + name : "PRODUCT_UNKNOWN" + build_source : "cmake" + get_source : "unknown" + environ : + { + "_LD_LIBRARY_PATH" : "${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "_PYTHONPATH" : ["${SOFT_ROOT_DIR}" + $VARS.sep + "lib" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR0}" + "${SOFT_ROOT_DIR}" + $VARS.sep + "${PYTHON_LIBDIR1}"] + } + depend : [] + opt_depend : [] + type : "sample" + source_dir : $APPLICATION.out_dir + $VARS.sep + 'SOURCES' + $VARS.sep + $name + build_dir : $APPLICATION.out_dir + $VARS.sep + 'BUILD' + $VARS.sep + $name +} \ No newline at end of file diff --git a/src/product.py b/src/product.py index 6ac6ee9..ec2f754 100644 --- a/src/product.py +++ b/src/product.py @@ -152,8 +152,11 @@ def product_is_sample(product_info): :return: True if the product has the sample type, else False :rtype: boolean ''' - ptype = product_info.type - return ptype.lower() == 'sample' + if 'type' in product_info: + ptype = product_info.type + return ptype.lower() == 'sample' + else: + return False def product_is_fixed(product_info): '''Know if a product is fixed diff --git a/test/_testTools/tools.py b/test/_testTools/tools.py index 61de6cf..a518644 100644 --- a/test/_testTools/tools.py +++ b/test/_testTools/tools.py @@ -19,6 +19,7 @@ import tempfile import sys import subprocess +import time class outRedirection(): '''redirection of standart output @@ -62,4 +63,15 @@ def check_proc_existence_and_kill(regex): pid = line2[1] kill9(pid) return pid - return 0 \ No newline at end of file + return 0 + +def check_proc_existence_and_kill_multi(regex, nb_kills, time_between_to_checks = 1): + found = False + i = 0 + while not found and i < nb_kills : + found = check_proc_existence_and_kill(regex) + if found: + return found + time.sleep(time_between_to_checks) + i+=1 + return 0 \ No newline at end of file diff --git a/test/config/option_value_2.py b/test/config/option_value_2.py index 20d80eb..d70ea1f 100644 --- a/test/config/option_value_2.py +++ b/test/config/option_value_2.py @@ -60,6 +60,31 @@ class TestConfig(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, 'OK') + def test_option_schema(self): + '''Test the display of the right value of "sat config -s" + ''' + + OK = 'KO' + + # output redirection + my_out = outRedirection() + + # The command to test + sat = Sat('') + sat.config('-s') + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + + if 'INTERNAL' in res: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') # test launch if __name__ == '__main__': diff --git a/test/log/launch_browser.py b/test/log/launch_browser.py index 793e433..c7f9104 100644 --- a/test/log/launch_browser.py +++ b/test/log/launch_browser.py @@ -41,28 +41,7 @@ sleep_time = 2 class TestLog(unittest.TestCase): '''Test of log command: launch of browser ''' - - def test_launch_browser(self): - '''Test the launch of browser when invoking the log command - ''' - - OK = "KO" - - sat = Sat("-oUSER.browser='konqueror'") - time.sleep(sleep_time) - cmd_log = threading.Thread(target=sat.log, args=('',)) - cmd_log.start() - - time.sleep(sleep_time) - - browser = sat.cfg.USER.browser - pid = check_proc_existence_and_kill(browser + ".*" + "hat\.xml") - - if pid: - OK = "OK" - # pyunit method to compare 2 str - self.assertEqual(OK, "OK") - + def test_write_xmllog(self): '''Test the write of xml log when invoking a command ''' @@ -241,7 +220,7 @@ class TestLog(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, "OK") - + def test_option_last(self): '''Test the option --last ''' @@ -268,7 +247,7 @@ class TestLog(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, "OK") - + def test_option_clean(self): '''Test the option --clean ''' @@ -321,7 +300,8 @@ class TestLog(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, "OK") - + + """ def test_option_full(self): '''Test the option --full ''' @@ -348,7 +328,7 @@ class TestLog(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, "OK") - + """ def test_description(self): '''Test the sat -h log ''' diff --git a/test/log/launch_browser2.py b/test/log/launch_browser2.py new file mode 100644 index 0000000..0f70b38 --- /dev/null +++ b/test/log/launch_browser2.py @@ -0,0 +1,63 @@ +#!/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 +import threading +import time + +# 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 +from tools import check_proc_existence_and_kill_multi +import HTMLTestRunner + +sleep_time = 2 + +class TestLog(unittest.TestCase): + '''Test of log command: launch of browser + ''' + def test_launch_browser(self): + '''Test the launch of browser when invoking the log command + ''' + + OK = "KO" + + sat = Sat("-oUSER.browser='konqueror'") + time.sleep(sleep_time) + cmd_log = threading.Thread(target=sat.log, args=('',)) + cmd_log.start() + + time.sleep(sleep_time) + + browser = sat.cfg.USER.browser + pid = check_proc_existence_and_kill_multi(browser + ".*" + "hat\.xml", 10) + + if pid: + OK = "OK" + # pyunit method to compare 2 str + self.assertEqual(OK, "OK") + +# test launch +if __name__ == '__main__': + HTMLTestRunner.main() diff --git a/test/prepare/test_patch.py b/test/prepare/test_patch.py new file mode 100644 index 0000000..eb014be --- /dev/null +++ b/test/prepare/test_patch.py @@ -0,0 +1,191 @@ +#!/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 +import shutil + +# 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 tools import outRedirection + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestPatch(unittest.TestCase): + '''Test of the patch command + ''' + + def test_patch_dev(self): + '''Test the patch command with a product in dev mode + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' + + sat = Sat("-oUSER.output_level=2") + + sat.config(appli) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + if os.path.exists(expected_src_dir): + shutil.rmtree(expected_src_dir) + + sat.source(appli + ' --product ' + product_name) + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + OK1 = 'KO' + if text == expected_text: + OK1 = 'OK' + + sat.patch(appli + ' --product ' + product_name) + + new_expected_text = 'HELLO WORLD MODIFIED\n' + f = open(expected_file_path, 'r') + text = f.readlines()[0] + + OK2 = 'KO' + if text == new_expected_text: + OK2 = 'OK' + + if (OK1, OK2)==('OK', 'OK'): + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_no_sources_found(self): + '''Test the patch command with a product with no sources found + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' + + sat = Sat('') + sat.config(appli) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + + if os.path.exists(expected_src_dir): + shutil.rmtree(expected_src_dir) + + # output redirection + my_out = outRedirection() + + sat.patch(appli + ' --product ' + product_name) + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + if "No sources found for the " + product_name +" product" in res: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_no_patch(self): + '''Test the patch command with a product without patch + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_ARCHIVE' + + sat = Sat() + + sat.source(appli + ' --product ' + product_name) + + # output redirection + my_out = outRedirection() + + sat.patch(appli + ' --product ' + product_name) + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + if "No patch for the " + product_name +" product" in res: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_invalid_patch(self): + '''Test the patch command with a product with a not valid patch + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' + + sat = Sat("-oPRODUCTS.PRODUCT_DEV.patches=['/']") + + sat.source(appli + ' --product ' + product_name) + + # output redirection + my_out = outRedirection() + + sat.patch(appli + ' --product ' + product_name) + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + if "Not a valid patch" in res: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h patch + ''' + + OK = "KO" + + import patch + + if "The patch command apply the patches on the sources of" in patch.description(): + OK = "OK" + + # pyunit method to compare 2 str + self.assertEqual(OK, "OK") + +# test launch +if __name__ == '__main__': + HTMLTestRunner.main() diff --git a/test/prepare/test_prepare.py b/test/prepare/test_prepare.py index 64c2c86..f03b6c8 100644 --- a/test/prepare/test_prepare.py +++ b/test/prepare/test_prepare.py @@ -19,7 +19,7 @@ import unittest import os import sys -import io +import shutil # get execution path testdir = os.path.dirname(os.path.realpath(__file__)) @@ -27,33 +27,106 @@ sys.path.append(os.path.join(testdir, '..', '..')) sys.path.append(os.path.join(testdir, '..', '_testTools')) sys.path.append(os.path.join(testdir, '..', '..','commands')) +import src + +from tools import outRedirection + from salomeTools import Sat import HTMLTestRunner -sleep_time = 3 - -class TestLog(unittest.TestCase): +class TestPrepare(unittest.TestCase): '''Test of the prepare command ''' - + + def test_prepare_dev(self): + '''Test the prepare command with a product in dev mode + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' + + sat = Sat() + + sat.config(appli) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + if os.path.exists(expected_src_dir): + shutil.rmtree(expected_src_dir) + + sat.prepare(appli + ' --product ' + product_name) + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + if text == expected_text: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + def test_prepare_all(self): - '''Test the prepare command with many ways to prepare + '''Test the prepare command with all products ''' - - OK = "KO" + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' sat = Sat() + sat.config(appli) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + if os.path.exists(expected_src_dir): + shutil.rmtree(expected_src_dir) + + sat.prepare(appli) + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + if text == expected_text: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + def test_prepare_option_sample_and_force(self): + '''Test the prepare command with all products + ''' + OK = 'KO' + + appli = 'appli-test' + + sat = Sat() + sat.config(appli) + try: - sat.prepare('appli-test') - OK = "OK" + sat.prepare(appli + " --no_sample --force") + OK = 'OK' except: pass + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h prepare + ''' + + OK = "KO" + + import prepare + if "The prepare command gets the sources" in prepare.description(): + OK = "OK" # pyunit method to compare 2 str self.assertEqual(OK, "OK") - # test launch if __name__ == '__main__': diff --git a/test/prepare/test_source.py b/test/prepare/test_source.py new file mode 100644 index 0000000..12831ef --- /dev/null +++ b/test/prepare/test_source.py @@ -0,0 +1,266 @@ +#!/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 +import shutil + +# 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 tools import outRedirection + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestSource(unittest.TestCase): + '''Test of the source command + ''' + + def test_source_archive(self): + '''Test the source command with archive product + ''' + appli = 'appli-test' + product_name = 'PRODUCT_ARCHIVE' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + f = open(expected_file_path, 'r') + text = f.read() + + # pyunit method to compare 2 str + self.assertEqual(text, expected_text) + + def test_source_git(self): + '''Test the source command with git product + ''' + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + f = open(expected_file_path, 'r') + text = f.read() + + # pyunit method to compare 2 str + self.assertEqual(text, expected_text) + + def test_source_cvs(self): + '''Test the source command with cvs product + ''' + appli = 'appli-test' + product_name = 'PRODUCT_CVS' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'README.FIRST.txt') + expected_text = 'Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE\n' + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + + # pyunit method to compare 2 str + self.assertEqual(text, expected_text) + + """ + def test_source_svn(self): + '''Test the source command with svn product + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_SVN' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'scripts', 'README') + expected_text = 'this directory contains scripts used by salomeTool' + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + + if expected_text in text: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + """ + + def test_source_native(self): + '''Test the source command with native product + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_NATIVE' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = os.path.join(sat.cfg.APPLICATION.out_dir, 'SOURCES', product_name) + if not os.path.exists(expected_src_dir): + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_source_fixed(self): + '''Test the source command with fixed product + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_FIXED' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + + if os.path.exists(expected_src_dir): + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_source_unknown(self): + '''Test the source command with unknown product + ''' + OK = 'KO' + + # output redirection + my_out = outRedirection() + + appli = 'appli-test' + product_name = 'PRODUCT_UNKNOWN' + + sat = Sat() + sat.source(appli + ' --product ' + product_name) + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + if "Unknown get source method" in res: + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_source_dev(self): + '''Test the source command with a product in dev mode + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_DEV' + + sat = Sat() + + sat.config(appli) + + expected_src_dir = src.product.get_product_config(sat.cfg, product_name).source_dir + expected_file_path = os.path.join(expected_src_dir, 'my_test_file.txt') + expected_text = 'HELLO WORLD\n' + + if os.path.exists(expected_src_dir): + shutil.rmtree(expected_src_dir) + + sat.source(appli + ' --product ' + product_name) + + f = open(expected_file_path, 'r') + text = f.readlines()[0] + OK1 = 'KO' + if text == expected_text: + OK1 = 'OK' + + # output redirection + my_out = outRedirection() + + sat.source(appli + ' --product ' + product_name) + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + OK2 = 'KO' + if "source directory already exists" in res: + OK2 = 'OK' + + # output redirection + my_out = outRedirection() + + sat.source(appli + ' --product ' + product_name + ' --force') + + # stop output redirection + my_out.end_redirection() + + # get results + res = my_out.read_results() + + OK3 = 'KO' + if "source directory already exists" not in res: + OK3 = 'OK' + + if (OK1, OK2, OK3)==('OK', 'OK', 'OK'): + OK = 'OK' + + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h source + ''' + + OK = "KO" + + import source + + if "gets the sources of the application" in source.description(): + 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 3de7995..bec400b 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -16,11 +16,18 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +rm -rf .coverage htmlcov + coverage run --source=../commands/config.py config/option_value.py > test_res.html coverage run --source=../commands/config.py -a config/option_value_2.py >> test_res.html coverage run --source=../commands/config.py -a config/create_user_pyconf.py >> test_res.html coverage run --source=../commands/config.py -a config/option_copy.py >> test_res.html coverage run --source=../commands/config.py -a config/option_edit.py >> test_res.html coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser.py >> test_res.html +coverage run --source=../commands/config.py,../commands/log.py,../src/xmlManager.py,../src/logger.py -a log/launch_browser2.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_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 html + +#firefox test_res.html htmlcov/index.html -- 2.39.2