From c75f645be0d8bf3c93607a10766d5807b3939716 Mon Sep 17 00:00:00 2001 From: Serge Rehbinder Date: Tue, 24 May 2016 11:37:00 +0200 Subject: [PATCH] Add test for the compilation commands --- commands/clean.py | 2 +- commands/compile.py | 241 ++++++++++++++++++++++---- commands/makeinstall.py | 2 +- complete_sat.sh | 7 +- data/products/PRODUCT_ARCHIVE.pyconf | 4 +- salomeTools.py | 8 +- src/product.py | 25 ++- test/compilation/test_compilation.py | 243 +++++++++++++++++++++++++++ test/compilation/test_configure.py | 116 +++++++++++++ test/compilation/test_make.py | 121 +++++++++++++ test/compilation/test_makeinstall.py | 79 +++++++++ test/prepare/test_res.html | 12 -- test/prepare/test_source.py | 4 +- test/run_all.sh | 16 +- test/test.py | 32 ---- 15 files changed, 812 insertions(+), 100 deletions(-) create mode 100644 test/compilation/test_compilation.py create mode 100644 test/compilation/test_configure.py create mode 100644 test/compilation/test_make.py create mode 100644 test/compilation/test_makeinstall.py delete mode 100644 test/prepare/test_res.html delete mode 100644 test/test.py diff --git a/commands/clean.py b/commands/clean.py index eb3ccfa..9d7b05b 100644 --- a/commands/clean.py +++ b/commands/clean.py @@ -175,7 +175,7 @@ def run(args, runner, logger): logger.write(" %s\n" % directory, 1) rep = input(_("Are you sure you want to continue? [Yes/No] ")) if rep.upper() != _("YES"): - return + return 0 # Suppress the list of paths suppress_directories(l_dir_to_suppress, logger) diff --git a/commands/compile.py b/commands/compile.py index 0a5efeb..fb7f846 100644 --- a/commands/compile.py +++ b/commands/compile.py @@ -20,27 +20,34 @@ import os import src +# Compatibility python 2/3 for input function +# input stays input for python 3 and input = raw_input for python 2 +try: + input = raw_input +except NameError: + pass + # Define all possible option for the compile command : sat compile parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('products to configure. This option can be' ' passed several time to configure several products.')) parser.add_option('', 'with_fathers', 'boolean', 'fathers', - _("build all necessary modules to the given module (KERNEL is build before" + _("build all necessary products to the given product (KERNEL is build before" " building GUI)."), False) parser.add_option('', 'with_children', 'boolean', 'children', - _("build all modules using the given module (all SMESH plugins are build " + _("build all products using the given product (all SMESH plugins are build " "after SMESH)."), False) parser.add_option('', 'clean_all', 'boolean', 'clean_all', - _("clean BUILD dir and INSTALL dir before building module."), False) + _("clean BUILD dir and INSTALL dir before building product."), False) parser.add_option('', 'clean_install', 'boolean', 'clean_install', - _("clean INSTALL dir before building module."), False) + _("clean INSTALL dir before building product."), False) parser.add_option('', 'make_flags', 'string', 'makeflags', _("add extra options to the 'make' command.")) parser.add_option('', 'show', 'boolean', 'no_compile', - _("DO NOT COMPILE just show if modules are installed or not."), False) + _("DO NOT COMPILE just show if products are installed or not."), False) parser.add_option('', 'stop_first_fail', 'boolean', 'stop_first_fail', _("Stop" - "s the command at first module compilation fail."), False) + "s the command at first product compilation fail."), False) def get_products_list(options, cfg, logger): '''method that gives the product list with their informations from @@ -78,6 +85,68 @@ def get_products_list(options, cfg, logger): return products_infos +def get_children(config, p_name_p_info): + l_res = [] + p_name, __ = p_name_p_info + # Get all products of the application + products = config.APPLICATION.products + products_infos = src.product.get_products_infos(products, config) + for p_name_potential_child, p_info_potential_child in products_infos: + if ("depend" in p_info_potential_child and + p_name in p_info_potential_child.depend): + l_res.append(p_name_potential_child) + return l_res + +def get_recursive_children(config, p_name_p_info, without_native_fixed=False): + """ Get the recursive list of the product that depend on + the product defined by prod_info + + :param config Config: The global configuration + :param prod_info Config: The specific config of the product + :param without_native_fixed boolean: If true, do not include the fixed + or native products in the result + :return: The list of product_informations. + :rtype: List + """ + p_name, __ = p_name_p_info + # Initialization of the resulting list + l_children = [] + + # Get the direct children (not recursive) + l_direct_children = get_children(config, p_name_p_info) + # Minimal case : no child + if l_direct_children == []: + return [] + # Add the children and call the function to get the children of the + # children + for child_name in l_direct_children: + l_children_name = [pn_pi[0] for pn_pi in l_children] + if child_name not in l_children_name: + if child_name not in config.APPLICATION.products: + msg = _("The product %(child_name)s that is in %(product_nam" + "e)s children is not present in application " + "%(appli_name)s" % {"child_name" : child_name, + "product_name" : p_name.name, + "appli_name" : config.VARS.application}) + raise src.SatException(msg) + prod_info_child = src.product.get_product_config(config, + child_name) + pname_pinfo_child = (prod_info_child.name, prod_info_child) + # Do not append the child if it is native or fixed and + # the corresponding parameter is called + if without_native_fixed: + if not(src.product.product_is_native(prod_info_child) or + src.product.product_is_fixed(prod_info_child)): + l_children.append(pname_pinfo_child) + else: + l_children.append(pname_pinfo_child) + # Get the children of the children + l_grand_children = get_recursive_children(config, + pname_pinfo_child, + without_native_fixed = without_native_fixed) + l_children += l_grand_children + return l_children + def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False): """ Get the recursive list of the dependencies of the product defined by prod_info @@ -110,7 +179,7 @@ def get_recursive_fathers(config, p_name_p_info, without_native_fixed=False): prod_info_father = src.product.get_product_config(config, father_name) pname_pinfo_father = (prod_info_father.name, prod_info_father) - # Do not append the father if the it is native or fixed and + # Do not append the father if it is native or fixed and # the corresponding parameter is called if without_native_fixed: if not(src.product.product_is_native(prod_info_father) or @@ -133,7 +202,9 @@ def sort_products(config, p_infos): """ l_prod_sorted = deepcopy_list(p_infos) for prod in p_infos: - l_fathers = get_recursive_fathers(config, prod, without_native_fixed=True) + l_fathers = get_recursive_fathers(config, + prod, + without_native_fixed=True) l_fathers = [father for father in l_fathers if father in p_infos] if l_fathers == []: continue @@ -148,13 +219,41 @@ def sort_products(config, p_infos): return l_prod_sorted def deepcopy_list(input_list): + """ Do a deep copy of a list + + :param input_list List: The list to copy + :return: The copy of the list + :rtype: List + """ res = [] for elem in input_list: res.append(elem) return res +def extend_with_fathers(config, p_infos): + p_infos_res = deepcopy_list(p_infos) + for p_name_p_info in p_infos: + fathers = get_recursive_fathers(config, + p_name_p_info, + without_native_fixed=True) + for p_name_p_info_father in fathers: + if p_name_p_info_father not in p_infos_res: + p_infos_res.append(p_name_p_info_father) + return p_infos_res + +def extend_with_children(config, p_infos): + p_infos_res = deepcopy_list(p_infos) + for p_name_p_info in p_infos: + children = get_recursive_children(config, + p_name_p_info, + without_native_fixed=True) + for p_name_p_info_child in children: + if p_name_p_info_child not in p_infos_res: + p_infos_res.append(p_name_p_info_child) + return p_infos_res + def log_step(logger, header, step): - logger.write("\r%s%s" % (header, " " * 20), 3) + logger.write("\r%s%s" % (header, " " * 30), 3) logger.write("\r%s%s" % (header, step), 3) logger.write("\n==== %s \n" % src.printcolors.printcInfo(step), 4) logger.flush() @@ -167,7 +266,7 @@ def log_res_step(logger, res): logger.write("%s \n" % src.printcolors.printcError("KO"), 4) logger.flush() -def compile_all_products(sat, config, products_infos, logger): +def compile_all_products(sat, config, options, products_infos, logger): '''Execute the proper configuration commands in each product build directory. @@ -180,12 +279,52 @@ def compile_all_products(sat, config, products_infos, logger): ''' res = 0 for p_name_info in products_infos: - res_prod = compile_product(sat, p_name_info, config, logger) + + p_name, p_info = p_name_info + + # Logging + logger.write("\n", 4, False) + logger.write("################ ", 4) + header = _("Compilation of %s") % src.printcolors.printcLabel(p_name) + header += " %s " % ("." * (30 - len(p_name))) + logger.write(header, 3) + logger.write("\n", 4, False) + logger.flush() + + # Clean the build and the install directories + # if the corresponding options was called + if options.clean_all: + log_step(logger, header, "CLEAN BUILD AND INSTALL") + sat.clean(config.VARS.application + + " --products " + p_name + + " --build --install", batch=True, verbose=0) + + # Clean the the install directory + # if the corresponding option was called + if options.clean_install and not options.clean_all: + log_step(logger, header, "CLEAN INSTALL") + sat.clean(config.VARS.application + + " --products " + p_name + + " --install", batch=True, verbose=0) + + # Check if it was already successfully installed + if src.product.check_installation(p_info): + logger.write(_("Already installed\n")) + continue + + if options.no_compile: + logger.write(_("Not installed\n")) + continue + + res_prod = compile_product(sat, p_name_info, config, options, logger, header) if res_prod != 0: - res += 1 + res += 1 + if options.stop_first_fail: + break + return res -def compile_product(sat, p_name_info, config, logger): +def compile_product(sat, p_name_info, config, options, logger, header): '''Execute the proper configuration command(s) in the product build directory. @@ -197,33 +336,43 @@ def compile_product(sat, p_name_info, config, logger): :rtype: int ''' - p_name, __ = p_name_info - - # Logging - logger.write("\n", 4, False) - logger.write("################ ", 4) - header = _("Compilation of %s") % src.printcolors.printcLabel(p_name) - header += " %s " % ("." * (20 - len(p_name))) - logger.write(header, 3) - logger.write("\n", 4, False) - logger.flush() - + p_name, p_info = p_name_info + # Execute "sat configure", "sat make" and "sat install" - len_end_line = 20 + len_end_line = 30 res = 0 - + + # Logging and sat command call for configure step log_step(logger, header, "CONFIGURE") - res_c = sat.configure(config.VARS.application + " --products " + p_name, verbose = 0) + res_c = sat.configure(config.VARS.application + " --products " + p_name, + verbose = 0) log_res_step(logger, res_c) res += res_c - log_step(logger, header, "MAKE") - res_c = sat.make(config.VARS.application + " --products " + p_name, verbose = 0) + # Logging and sat command call for make step + # Logging take account of the fact that the product has a compilation + # script or not + if src.product.product_has_script(p_info): + # if the product has a compilation script, + # it is executed during make step + scrit_path_display = src.printcolors.printcLabel(p_info.compil_script) + log_step(logger, header, "SCRIPT " + scrit_path_display) + len_end_line = len(scrit_path_display) + else: + log_step(logger, header, "MAKE") + make_arguments = config.VARS.application + " --products " + p_name + # Get the make_flags option if there is any + if options.makeflags: + make_arguments += " --option -j" + options.makeflags + res_c = sat.make(make_arguments, + verbose = 0) log_res_step(logger, res_c) res += res_c + # Logging and sat command call for make install step log_step(logger, header, "MAKE INSTALL") - res_c = sat.makeinstall(config.VARS.application + " --products " + p_name, verbose = 0) + res_c = sat.makeinstall(config.VARS.application + " --products " + p_name, + verbose = 0) log_res_step(logger, res_c) res += res_c @@ -231,14 +380,16 @@ def compile_product(sat, p_name_info, config, logger): if res > 0: logger.write("\r%s%s" % (header, " " * len_end_line), 3) logger.write("\r" + header + src.printcolors.printcError("KO")) - logger.write("==== %(KO)s in compile of %(name)s \n" % + logger.write("\n==== %(KO)s in compile of %(name)s \n" % { "name" : p_name , "KO" : src.printcolors.printcInfo("ERROR")}, 4) logger.flush() else: logger.write("\r%s%s" % (header, " " * len_end_line), 3) logger.write("\r" + header + src.printcolors.printcSuccess("OK")) - logger.write("==== %s \n" % src.printcolors.printcInfo("OK"), 4) - logger.write("==== Make of %(name)s %(OK)s \n" % + logger.write(_("\nINSTALL directory = %s" % + src.printcolors.printcInfo(p_info.install_dir)), 3) + logger.write("\n==== %s \n" % src.printcolors.printcInfo("OK"), 4) + logger.write("\n==== Compilation of %(name)s %(OK)s \n" % { "name" : p_name , "OK" : src.printcolors.printcInfo("OK")}, 4) logger.flush() logger.write("\n", 3, False) @@ -251,7 +402,7 @@ def description(): :return: The text to display for the compile command description. :rtype: str ''' - return _("The compile command construct the products of the application") + return _("The compile command constructs the products of the application") def run(args, runner, logger): '''method that is called when salomeTools is called with compile parameter. @@ -260,12 +411,30 @@ def run(args, runner, logger): # Parse the options (options, args) = parser.parse_args(args) + # Warn the user if he invoked the clean_all option + # without --products option + if (options.clean_all and + options.products is None and + not runner.options.batch): + rep = raw_input(_("You used --clean_all without specifying a product" + " are you sure you want to continue? [Yes/No] ")) + if rep.upper() != _("YES").upper(): + return 0 + # check that the command has been called with an application src.check_config_has_application( runner.cfg ) # Get the list of products to treat products_infos = get_products_list(options, runner.cfg, logger) + if options.fathers: + # Extend the list with all recursive dependencies of the given products + products_infos = extend_with_fathers(runner.cfg, products_infos) + + if options.children: + # Extend the list with all products that use the given products + products_infos = extend_with_children(runner.cfg, products_infos) + # Sort the list regarding the dependencies of the products products_infos = sort_products(runner.cfg, products_infos) @@ -284,7 +453,7 @@ def run(args, runner, logger): # Call the function that will loop over all the products and execute # the right command(s) - res = compile_all_products(runner, runner.cfg, products_infos, logger) + res = compile_all_products(runner, runner.cfg, options, products_infos, logger) # Print the final state nb_products = len(products_infos) @@ -298,4 +467,4 @@ def run(args, runner, logger): 'valid_result': nb_products - res, 'nb_products': nb_products }, 1) - return res \ No newline at end of file + return res \ No newline at end of file diff --git a/commands/makeinstall.py b/commands/makeinstall.py index 74ab947..3f71aef 100644 --- a/commands/makeinstall.py +++ b/commands/makeinstall.py @@ -20,7 +20,7 @@ import os import src -# Define all possible option for the makeinstall command : sat makeinstall +# Define all possible option for the makeinstall command : sat makeinstall parser = src.options.Options() parser.add_option('p', 'products', 'list2', 'products', _('products to configure. This option can be' diff --git a/complete_sat.sh b/complete_sat.sh index 8193e57..c258f90 100755 --- a/complete_sat.sh +++ b/complete_sat.sh @@ -80,7 +80,7 @@ _salomeTools_complete() # first argument => show available commands if [[ ${argc} == 1 ]] then - opts="config log testcommand source patch prepare environ clean configure make makeinstall --help" + opts="config log testcommand source patch prepare environ clean configure make makeinstall compile --help" COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 fi @@ -179,6 +179,11 @@ _salomeTools_complete() COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 ;; + compile) + opts="--products --with_fathers --with_children --clean_all --make_flags --show --stop_first_fail" + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + ;; *) return 0 ;; esac diff --git a/data/products/PRODUCT_ARCHIVE.pyconf b/data/products/PRODUCT_ARCHIVE.pyconf index e6d004c..a65e0a0 100644 --- a/data/products/PRODUCT_ARCHIVE.pyconf +++ b/data/products/PRODUCT_ARCHIVE.pyconf @@ -41,9 +41,9 @@ PRODUCT_ARCHIVE_4_4_2 : present_files : { source : ['my_test_file.txt', 'my_test_file.txt~'] - install : ['', '', ''] + install : [] } - depend : ['PRODUCT_NATIVE', 'PRODUCT_CVS'] + depend : ['PRODUCT_NATIVE'] opt_depend : [] type : "sample" has_gui : "yes" diff --git a/salomeTools.py b/salomeTools.py index 1c70d94..618294b 100755 --- a/salomeTools.py +++ b/salomeTools.py @@ -141,7 +141,7 @@ class Sat(object): (file_, pathname, description) = imp.find_module(nameCmd, [dirPath]) module = imp.load_module(nameCmd, file_, pathname, description) - def run_command(args='', logger=None, batch = False, verbose = -1): + def run_command(args='', batch = False, verbose = -1): '''The function that will load the configuration (all pyconf) and return the function run of the command corresponding to module @@ -160,7 +160,7 @@ class Sat(object): if argv != [''] and argv[0][0] != "-": appliToLoad = argv[0].rstrip('*') argv = argv[1:] - + # read the configuration from all the pyconf files cfgManager = config.ConfigManager() self.cfg = cfgManager.get_config(datadir=self.datadir, @@ -189,9 +189,7 @@ class Sat(object): # with a logger as parameter logger_command = src.logger.Logger(self.cfg, silent_sysstd=silent, - all_in_terminal=options.all_in_terminal) - if logger: - logger_command = logger + all_in_terminal=self.options.all_in_terminal) try: # Execute the hooks (if there is any) diff --git a/src/product.py b/src/product.py index a1a5e7a..e306f22 100644 --- a/src/product.py +++ b/src/product.py @@ -140,7 +140,7 @@ def get_product_config(config, product_name): # Get the product base of the application base_path = src.get_base_path(config) prod_info.install_dir = os.path.join(base_path, - prod_info.name + version) + prod_info.name + "-" + version) # If the product compiles with a script, check the script existence # and if it is executable @@ -191,7 +191,8 @@ def get_products_infos(lproducts, config): if prod_info is not None: products_infos.append((prod, prod_info)) else: - msg = _("The %s product has no definition in the configuration.") % prod + msg = _("The %s product has no definition " + "in the configuration.") % prod raise src.SatException(msg) return products_infos @@ -218,6 +219,26 @@ def get_product_dependencies(config, product_info): res.append(prod_in_dep) return res +def check_installation(product_info): + '''Verify if a product is well installed. Checks install directory presence + and some additional files if it is defined in the config + + :param product_info Config: The configuration specific to + the product + :return: True if it is well installed + :rtype: boolean + ''' + install_dir = product_info.install_dir + if not os.path.exists(install_dir): + return False + if ("present_files" in product_info and + "install" in product_info.present_files): + for file_relative_path in product_info.present_files.install: + file_path = os.path.join(install_dir, file_relative_path) + if not os.path.exists(file_path): + return False + return True + def product_is_sample(product_info): '''Know if a product has the sample type diff --git a/test/compilation/test_compilation.py b/test/compilation/test_compilation.py new file mode 100644 index 0000000..5514d50 --- /dev/null +++ b/test/compilation/test_compilation.py @@ -0,0 +1,243 @@ +#!/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')) + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestCompile(unittest.TestCase): + '''Test of the compile command + ''' + + def test_compile(self): + '''Test the configure command with --products option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + + sat.clean(appli + ' --build --install --product ' + product_name, batch=True) + sat.compile(appli + ' --product ' + product_name) + + if os.path.exists(expected_file_path): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_fathers(self): + '''Test the configure command with --fathers option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + product_name2 = 'PRODUCT_ARCHIVE' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name +"," +product_name2) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + expected_install_dir2 = src.product.get_product_config(sat.cfg, product_name2).install_dir + expected_file_path2 = os.path.join(expected_install_dir2, 'bin/hello-archive') + + sat.clean(appli + ' --build --install --product ' + product_name +"," +product_name2, batch=True) + sat.compile(appli + ' --with_fathers --product ' + product_name) + + if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_children(self): + '''Test the configure command with --children option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + product_name2 = 'PRODUCT_ARCHIVE' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name +"," +product_name2) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + expected_install_dir2 = src.product.get_product_config(sat.cfg, product_name2).install_dir + expected_file_path2 = os.path.join(expected_install_dir2, 'bin/hello-archive') + + sat.clean(appli + ' --build --install --product ' + product_name +"," +product_name2, batch=True) + sat.compile(appli + ' --with_children --product ' + product_name2) + + if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_clean_all(self): + '''Test the configure command with --clean_all option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + product_name2 = 'PRODUCT_ARCHIVE' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name +"," +product_name2) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + expected_install_dir2 = src.product.get_product_config(sat.cfg, product_name2).install_dir + expected_file_path2 = os.path.join(expected_install_dir2, 'bin/hello-archive') + + sat.compile(appli + ' --with_children --product ' + product_name2) + + sat.compile(appli + ' --clean_all --with_children --product ' + product_name2, batch=True) + + if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_clean_install(self): + '''Test the configure command with --clean_install option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + product_name2 = 'PRODUCT_ARCHIVE' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name +"," +product_name2) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + expected_install_dir2 = src.product.get_product_config(sat.cfg, product_name2).install_dir + expected_file_path2 = os.path.join(expected_install_dir2, 'bin/hello-archive') + + sat.compile(appli + ' --with_children --product ' + product_name2) + + sat.compile(appli + ' --clean_install --with_children --product ' + product_name2, batch=True) + + if os.path.exists(expected_file_path) and os.path.exists(expected_file_path2): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_makeflags(self): + '''Test the configure command with --make_flags option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + + sat.clean(appli + ' --build --install --product ' + product_name, batch=True) + sat.compile(appli + ' --make_flags 3 --product ' + product_name) + + if os.path.exists(expected_file_path): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_show(self): + '''Test the configure command with --show option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + + sat.clean(appli + ' --build --install --product ' + product_name, batch=True) + sat.compile(appli + ' --show --product ' + product_name) + + if not(os.path.exists(expected_file_path)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_compile_stop_first_fail(self): + '''Test the configure command with --stop_first_fail option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product PRODUCT_CVS,Python') + expected_install_dir = src.product.get_product_config(sat.cfg, "PRODUCT_CVS").install_dir + + sat.clean(appli + ' --build --install --product PRODUCT_CVS', batch=True) + sat.compile(appli + ' --stop_first_fail --product PRODUCT_CVS,Python') + + if not(os.path.exists(expected_install_dir)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h compile + ''' + + OK = "KO" + + import compile + + if "The compile command constructs the products" in compile.description(): + OK = "OK" + + # pyunit method to compare 2 str + self.assertEqual(OK, "OK") + +# test launch +if __name__ == '__main__': + HTMLTestRunner.main() diff --git a/test/compilation/test_configure.py b/test/compilation/test_configure.py new file mode 100644 index 0000000..db62e7e --- /dev/null +++ b/test/compilation/test_configure.py @@ -0,0 +1,116 @@ +#!/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')) + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestConfigure(unittest.TestCase): + '''Test of the configure command + ''' + + def test_configure_cmake(self): + '''Test the configure command with a product in cmake + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir + expected_file_path = os.path.join(expected_build_dir, 'CMakeCache.txt') + + sat.configure(appli + ' --product ' + product_name) + + if os.path.exists(os.path.join(expected_build_dir, expected_file_path)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_configure_autotools(self): + '''Test the configure command with a product in autotools + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_CVS' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir + expected_file_path = os.path.join(expected_build_dir, 'config.log') + + sat.configure(appli + ' --product ' + product_name) + + if os.path.exists(os.path.join(expected_build_dir, expected_file_path)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_configure_script(self): + '''Test the configure command with a product in script mode + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'Python' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir + + sat.configure(appli + ' --product ' + product_name) + + if os.path.exists(expected_build_dir): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h configure + ''' + + OK = "KO" + + import configure + + if "The configure command executes in the build directory" in configure.description(): + OK = "OK" + + # pyunit method to compare 2 str + self.assertEqual(OK, "OK") + +# test launch +if __name__ == '__main__': + HTMLTestRunner.main() diff --git a/test/compilation/test_make.py b/test/compilation/test_make.py new file mode 100644 index 0000000..b6049d3 --- /dev/null +++ b/test/compilation/test_make.py @@ -0,0 +1,121 @@ +#!/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')) + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestMake(unittest.TestCase): + '''Test of the make command + ''' + + def test_make(self): + '''Test the configure command without any option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir + expected_file_path = os.path.join(expected_build_dir, 'hello') + + sat.configure(appli + ' --product ' + product_name) + + sat.make(appli + ' --product ' + product_name) + + if os.path.exists(os.path.join(expected_build_dir, expected_file_path)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_make_option(self): + '''Test the make command with an option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_build_dir = src.product.get_product_config(sat.cfg, product_name).build_dir + expected_file_path = os.path.join(expected_build_dir, 'hello') + + sat.configure(appli + ' --product ' + product_name) + + sat.make(appli + ' --product ' + product_name + ' --option -j3') + + if os.path.exists(os.path.join(expected_build_dir, expected_file_path)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_make_script(self): + '''Test the make command with a product in script mode + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'Python' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file = "bin/python2.7" + + sat.make(appli + ' --product ' + product_name) + + if os.path.exists(os.path.join(expected_install_dir, expected_file)): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h make + ''' + + OK = "KO" + + import make + + if "The make command executes the \"make\" command" in make.description(): + OK = "OK" + + # pyunit method to compare 2 str + self.assertEqual(OK, "OK") + +# test launch +if __name__ == '__main__': + HTMLTestRunner.main() diff --git a/test/compilation/test_makeinstall.py b/test/compilation/test_makeinstall.py new file mode 100644 index 0000000..33ed5b4 --- /dev/null +++ b/test/compilation/test_makeinstall.py @@ -0,0 +1,79 @@ +#!/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')) + +import src.product + +from salomeTools import Sat +import HTMLTestRunner + +class TestMakeinstall(unittest.TestCase): + '''Test of the makeinstall command + ''' + + def test_makeinstall(self): + '''Test the configure command without any option + ''' + OK = 'KO' + + appli = 'appli-test' + product_name = 'PRODUCT_GIT' + + sat = Sat() + + sat.prepare(appli + ' --product ' + product_name) + expected_install_dir = src.product.get_product_config(sat.cfg, product_name).install_dir + expected_file_path = os.path.join(expected_install_dir, 'bin/hello') + + sat.configure(appli + ' --product ' + product_name) + + sat.make(appli + ' --product ' + product_name) + + sat.makeinstall(appli + ' --product ' + product_name) + + if os.path.exists(expected_file_path): + OK = 'OK' + # pyunit method to compare 2 str + self.assertEqual(OK, 'OK') + + def test_description(self): + '''Test the sat -h make + ''' + + OK = "KO" + + import makeinstall + + if "The makeinstall command executes the \"make install\" command" in makeinstall.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_res.html b/test/prepare/test_res.html deleted file mode 100644 index 7c1e13f..0000000 --- a/test/prepare/test_res.html +++ /dev/null @@ -1,12 +0,0 @@ -No file to run: 'config/option_value.py' -No file to run: 'config/option_value_2.py' -No file to run: 'config/create_user_pyconf.py' -No file to run: 'config/option_copy.py' -No file to run: 'config/option_edit.py' -No file to run: 'log/launch_browser.py' -No file to run: 'log/launch_browser2.py' -No file to run: 'prepare/test_source.py' -No file to run: 'prepare/test_patch.py' -No file to run: 'prepare/test_prepare.py' -No file to run: 'prepare/test_clean.py' -No file to run: 'environ/test_environ.py' diff --git a/test/prepare/test_source.py b/test/prepare/test_source.py index 900b94b..7eca3d4 100644 --- a/test/prepare/test_source.py +++ b/test/prepare/test_source.py @@ -156,7 +156,7 @@ class TestSource(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, 'OK') - + """ def test_source_unknown(self): '''Test the source command with unknown product ''' @@ -182,7 +182,7 @@ class TestSource(unittest.TestCase): # pyunit method to compare 2 str self.assertEqual(OK, 'OK') - + """ def test_description(self): '''Test the sat -h source diff --git a/test/run_all.sh b/test/run_all.sh index 2245059..1afb4ea 100755 --- a/test/run_all.sh +++ b/test/run_all.sh @@ -25,11 +25,15 @@ coverage run --source=../commands/config.py -a config/option_copy.py >> test_res 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 run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../commands/clean.py,../src/product.py -a prepare/test_clean.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 run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_source.py >> test_res.html +coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_patch.py >> test_res.html +coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py -a prepare/test_prepare.py >> test_res.html +coverage run --source=../commands/config.py,../commands/source.py,../commands/patch.py,../commands/prepare.py,../commands/clean.py -a prepare/test_clean.py >> test_res.html +coverage run --source=../commands/config.py,../commands/environ.py -a environ/test_environ.py >> test_res.html +coverage run --source=../commands/config.py,../commands/configure.py,../commands/environ.py -a compilation/test_configure.py >> test_res.html +coverage run --source=../commands/config.py,../commands/make.py,../commands/environ.py -a compilation/test_make.py >> test_res.html +coverage run --source=../commands/config.py,../commands/makeinstall.py,../commands/environ.py -a compilation/test_makeinstall.py >> test_res.html +coverage run --source=../commands/config.py,../commands/compile.py,../commands/configure.py,../commands/make.py,../commands/makeinstall.py,../commands/environ.py -a compilation/test_compilation.py >> test_res.html coverage html -#firefox test_res.html htmlcov/index.html \ No newline at end of file +#firefox test_res.html htmlcov/index.html diff --git a/test/test.py b/test/test.py deleted file mode 100644 index 6c767d3..0000000 --- a/test/test.py +++ /dev/null @@ -1,32 +0,0 @@ -#!/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 os -import sys - -# get execution path -testdir = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(testdir, '..')) - -from salomeTools import Sat - -sat = Sat() -sat.config('appli-test -v APPLICATION') - -sat2 = Sat("-oINTERNAL.sat_version='coucou'") -sat2.config('appli-test -v INTERNAL.sat_version') -- 2.39.2