From: Christian Van Wambeke Date: Fri, 4 May 2018 14:45:52 +0000 (+0200) Subject: begin fix test X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=846097b4078ccaf6e3acef03be9a2d049381a663;p=tools%2Fsat.git begin fix test --- diff --git a/commands/package.py b/commands/package.py index 5042c81..5360f03 100644 --- a/commands/package.py +++ b/commands/package.py @@ -1114,22 +1114,21 @@ def find_product_scripts_and_pyconf(p_name, """ # read the pyconf of the product - product_pyconf_path = UTS.find_file_in_lpath(p_name + ".pyconf", - config.PATHS.PRODUCTPATH) - product_pyconf_cfg = PYCONF.Config(product_pyconf_path) + namePyconf = p_name + ".pyconf" + rc = UTS.find_file_in_lpath(namePyconf, config.PATHS.PRODUCTPATH).raiseIfKo() + cfg = PYCONF.Config(rc.getValue()) # find the compilation script if any if PROD.product_has_script(p_info): compil_script_path = UTS.Path(p_info.compil_script) compil_script_path.copy(compil_scripts_tmp_dir) - product_pyconf_cfg[p_info.section].compil_script = os.path.basename( - p_info.compil_script) + cfg[p_info.section].compil_script = os.path.basename(p_info.compil_script) # find the environment script if any if PROD.product_has_env_script(p_info): env_script_path = UTS.Path(p_info.environ.env_script) env_script_path.copy(env_scripts_tmp_dir) - product_pyconf_cfg[p_info.section].environ.env_script = os.path.basename( - p_info.environ.env_script) + cfg[p_info.section].environ.env_script = os.path.basename(p_info.environ.env_script) + # find the patches if any if PROD.product_has_patches(p_info): patches = PYCONF.Sequence() @@ -1138,33 +1137,28 @@ def find_product_scripts_and_pyconf(p_name, p_path.copy(patches_tmp_dir) patches.append(os.path.basename(patch_path), "") - product_pyconf_cfg[p_info.section].patches = patches + cfg[p_info.section].patches = patches if with_vcs: # put in the pyconf file the resolved values for info in ["git_info", "cvs_info", "svn_info"]: if info in p_info: for key in p_info[info]: - product_pyconf_cfg[p_info.section][info][key] = p_info[ - info][key] + cfg[p_info.section][info][key] = p_info[info][key] else: # if the product is not archive, then make it become archive. if PROD.product_is_vcs(p_info): - product_pyconf_cfg[p_info.section].get_source = "archive" - if not "archive_info" in product_pyconf_cfg[p_info.section]: - product_pyconf_cfg[p_info.section].addMapping("archive_info", - PYCONF.Mapping(product_pyconf_cfg), - "") - product_pyconf_cfg[p_info.section - ].archive_info.archive_name = p_info.name + ".tgz" + cfg[p_info.section].get_source = "archive" + if not "archive_info" in cfg[p_info.section]: + cfg[p_info.section].addMapping("archive_info", PYCONF.Mapping(cfg), "") + cfg[p_info.section].archive_info.archive_name = p_info.name + ".tgz" # write the pyconf file to the temporary project location - product_tmp_pyconf_path = os.path.join(products_pyconf_tmp_dir, - p_name + ".pyconf") - ff = open(product_tmp_pyconf_path, 'w') - ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n") - product_pyconf_cfg.__save__(ff, 1) - ff.close() + pyconf_path = os.path.join(products_pyconf_tmp_dir, namePyconf) + with open(pyconf_path, 'w') as f: + f.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n") + cfg.__save__(f, 1) + return def find_application_pyconf(config, application_tmp_dir): """ @@ -1176,28 +1170,24 @@ def find_application_pyconf(config, application_tmp_dir): The path to the temporary application scripts directory of the project. """ # read the pyconf of the application - application_name = config.VARS.application - application_pyconf_path = UTS.find_file_in_lpath( - application_name + ".pyconf", - config.PATHS.APPLICATIONPATH) - application_pyconf_cfg = PYCONF.Config(application_pyconf_path) + name = config.VARS.application + namePyconf = name + ".pyconf" + rc = UTS.find_file_in_lpath(namePyconf, config.PATHS.APPLICATIONPATH).raiseIfKo() + cfg = PYCONF.Config(rc.getValue()) # Change the workdir - application_pyconf_cfg.APPLICATION.workdir = PYCONF.Reference( - application_pyconf_cfg, - PYCONF.DOLLAR, - 'VARS.salometoolsway + $VARS.sep + ".."') + cfg.APPLICATION.workdir = PYCONF.Reference( + cfg, PYCONF.DOLLAR, 'VARS.salometoolsway + $VARS.sep + ".."') # Prevent from compilation in base - application_pyconf_cfg.APPLICATION.no_base = "yes" + cfg.APPLICATION.no_base = "yes" # write the pyconf file to the temporary application location - application_tmp_pyconf_path = os.path.join(application_tmp_dir, - application_name + ".pyconf") - ff = open(application_tmp_pyconf_path, 'w') - ff.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n") - application_pyconf_cfg.__save__(ff, 1) - ff.close() + pyconf_path = os.path.join(application_tmp_dir, namePyconf) + with open(pyconf_path, 'w') as f: + f.write("#!/usr/bin/env python\n#-*- coding:utf-8 -*-\n\n") + cfg.__save__(f, 1) + return def project_package(project_file_path, tmp_working_dir): """ diff --git a/src/architecture.py b/src/architecture.py index f238fa2..24bd1a2 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -59,17 +59,17 @@ def _lsb_release(args): path = lsb_path + ":" + path from subprocess import Popen, PIPE - res = Popen(['lsb_release', args], env={'PATH': path}, - stdout=PIPE).communicate()[0][:-1] + p = Popen(['lsb_release', args], env={'PATH': path}, stdout=PIPE) + res = p.communicate()[0][:-1] # in case of python3, convert byte to str if isinstance(res, bytes): res = res.decode() return res except OSError: - sys.stderr.write(_(u"lsb_release not installed\n")) - sys.stderr.write(_(u"You can define $LSB_PATH to give" - " the path to lsb_release\n")) - sys.exit(-1) + msg = _("""\ +lsb_release not installed. +You can define $LSB_PATH to give the path to lsb_release""") + raise Exception(msg) def get_distribution(codes): """Gets the code for the distribution @@ -88,10 +88,10 @@ def get_distribution(codes): if codes is not None and distrib in codes: distrib = codes[distrib] else: - sys.stderr.write(_(u"Unknown distribution: '%s'\n") % distrib) - sys.stderr.write(_(u"Please add your distribution to" - " src/internal_config/distrib.pyconf\n")) - sys.exit(-1) + msg = _("""\ +Unknown distribution: '%s' +Please add your distribution to src/internal_config/distrib.pyconf.""") % distrib + raise Exception(msg) return distrib diff --git a/src/configManager.py b/src/configManager.py index ffa9051..029cd3e 100644 --- a/src/configManager.py +++ b/src/configManager.py @@ -373,11 +373,11 @@ class ConfigManager: if application is not None: PYCONF.streamOpener = ConfigOpener(cfg.PATHS.PRODUCTPATH) for product_name in application_cfg.APPLICATION.products.keys(): - # Loop on all files that are in softsDir directory - # and read their config + # Loop on all files that are in softsDir directory and read their config product_file_name = product_name + ".pyconf" - product_file_path = UTS.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH) - if product_file_path: + rc = UTS.find_file_in_lpath(product_file_name, cfg.PATHS.PRODUCTPATH) + if rc.isOk(): + product_file_path = rc.getValue() products_dir = os.path.dirname(product_file_path) try: prod_cfg = PYCONF.Config(open(product_file_path), PWD=("", products_dir)) @@ -449,7 +449,7 @@ class ConfigManager: cfg_name = self.get_user_config_file() cfg = PYCONF.Config() - cfg.addMapping('USER', PYCONF.Mapping(user_cfg), "") + cfg.addMapping('USER', PYCONF.Mapping(cfg), "") USER = cfg.USER USER.addMapping('cvs_user', config.VARS.user, diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 8a2c6a5..3724094 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -712,7 +712,7 @@ class ScreenEnviron(FileEnviron): # The SALOME launcher template withProfile = """\ -#! /usr/bin/env python +#!/usr/bin/env python ################################################################ # WARNING: this file is automatically generated by SalomeTools # @@ -722,6 +722,8 @@ withProfile = """\ import os import sys +_KO = 1 +_OK = 0 # Add the pwdPath to able to run the launcher after unpacking a package # Used only in case of a salomeTools package @@ -739,7 +741,7 @@ def __initialize(): setOmniOrbUserPath() except Exception, e: print e - sys.exit(1) + sys.exit(_KO) # End of preliminary work def main(args): @@ -749,13 +751,13 @@ def main(args): if args == ['--help']: from salomeContext import usage usage() - sys.exit(0) + sys.exit(_OK) #from salomeContextUtils import getConfigFileNames #configFileNames, args, unexisting = getConfigFileNames( args, checkExistence=True ) #if len(unexisting) > 0: # print "ERROR: unexisting configuration file(s): " + ', '.join(unexisting) - # sys.exit(1) + # sys.exit(_KO) # Create a SalomeContext which parses configFileNames to initialize environment try: @@ -785,7 +787,7 @@ def main(args): except SalomeContextException, e: import logging logging.getLogger("salome").error(e) - sys.exit(1) + sys.exit(_KO) # def addToSpecial(self, name, value, pathSep=None): "add special dangerous cases: TCLLIBPATH PV_PLUGIN_PATH etc..." diff --git a/src/product.py b/src/product.py index 32d13d4..63bcfd4 100644 --- a/src/product.py +++ b/src/product.py @@ -149,20 +149,19 @@ def get_product_config(config, product_name, with_install_dir=True): # If prod_info is still None, it means that there is no product definition # in the config. The user has to provide it. if prod_info is None: - prod_pyconf_path = UTS.find_file_in_lpath(product_name + ".pyconf", - config.PATHS.PRODUCTPATH) - if not prod_pyconf_path: + rc = UTS.find_file_in_lpath(product_name + ".pyconf", config.PATHS.PRODUCTPATH) + if not rc.isOk(): msg = _("""\ No definition found for the product %(1)s. -Please create a %(2)s.pyconf file somewhere in:\n%(3)s""") % { - "1": product_name, - "2": product_name, - "3": config.PATHS.PRODUCTPATH } +Please create a %(2)s.pyconf file somewhere in:\n%(3)s""") % \ + {"1": product_name, "2": product_name, "3": config.PATHS.PRODUCTPATH } else: + prod_pyconf_path = rc.getValue() msg = _("""\ No definition corresponding to the version %(1)s was found in the file: - %(2)s. -Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path} +%(2)s. +Please add a section in it.""") % \ + {"1" : vv, "2" : prod_pyconf_path} raise Exception(msg) # Set the debug, dev and version keys @@ -178,25 +177,22 @@ Please add a section in it.""") % {"1" : vv, "2" : prod_pyconf_path} "") if "archive_name" not in prod_info.archive_info: arch_name = product_name + "-" + version + ".tar.gz" - arch_path = UTS.find_file_in_lpath(arch_name, - config.PATHS.ARCHIVEPATH) - if not arch_path: + rc = UTS.find_file_in_lpath(arch_name, config.PATHS.ARCHIVEPATH) + if not rc.isOk(): msg = _("Archive %(1)s for %(2)s not found.\n") % \ {"1" : arch_name, "2" : prod_info.name} raise Exception(msg) - prod_info.archive_info.archive_name = arch_path + prod_info.archive_info.archive_name = rc.getValue() else: - if (os.path.basename(prod_info.archive_info.archive_name) == - prod_info.archive_info.archive_name): + basename = os.path.basename(prod_info.archive_info.archive_name) + if (basename == prod_info.archive_info.archive_name): arch_name = prod_info.archive_info.archive_name - arch_path = UTS.find_file_in_lpath( - arch_name, - config.PATHS.ARCHIVEPATH) - if not arch_path: + rc = UTS.find_file_in_lpath(arch_name, config.PATHS.ARCHIVEPATH) + if not rc.isOk(): msg = _("Archive %(1)s for %(2)s not found:\n") % \ {"1" : arch_name, "2" : prod_info.name} raise Exception(msg) - prod_info.archive_info.archive_name = arch_path + prod_info.archive_info.archive_name = rc.getValue() # If the product compiles with a script, check the script existence # and if it is executable @@ -213,58 +209,53 @@ Please provide a 'compil_script' key in its definition.""") % product_name script_name = os.path.basename(script) if script == script_name: # Only a name is given. Search in the default directory - script_path = UTS.find_file_in_lpath(script_name, - config.PATHS.PRODUCTPATH, - "compil_scripts") - if not script_path: - raise Exception( - _("Compilation script not found: %s") % script_name) - prod_info.compil_script = script_path + rc = UTS.find_file_in_lpath(script_name, config.PATHS.PRODUCTPATH, "compil_scripts") + if not rc.isOk(): + raise Exception(_("Compilation script not found: %s") % script_name) if ARCH.is_windows(): - prod_info.compil_script = prod_info.compil_script[:-len(".sh")] + ".bat" + prod_info.compil_script = rc.getValue()[:-len(".sh")] + ".bat" + else: + prod_info.compil_script = rc.getValue() + '''# TODO cvw no logger, no message, no raise, later... # Check that the script is executable if not os.access(prod_info.compil_script, os.X_OK): - #raise Exception( - # _("Compilation script cannot be executed: %s") % - # prod_info.compil_script) + #raise Exception(_("Compilation script cannot be executed: %s") % prod_info.compil_script) print("Compilation script cannot be executed: %s" % prod_info.compil_script) + ''' # Get the full paths of all the patches if product_has_patches(prod_info): patches = [] for patch in prod_info.patches: - patch_path = patch - # If only a filename, then search for the patch in the PRODUCTPATH - if os.path.basename(patch_path) == patch_path: - # Search in the PRODUCTPATH/patches - patch_path = UTS.find_file_in_lpath(patch, - config.PATHS.PRODUCTPATH, - "patches") - if not patch_path: - msg = _("Patch %(1)s for %(2)s not found:\n") % \ - {"1" : patch, "2" : prod_info.name} - raise Exception(msg) - patches.append(patch_path) + patch_path = patch + # If only a filename, then search for the patch in the PRODUCTPATH + if os.path.basename(patch_path) == patch_path: + # Search in the PRODUCTPATH/patches + rc = UTS.find_file_in_lpath(patch, config.PATHS.PRODUCTPATH, "patches") + if not rc.isOk(): + msg = _("Patch %s for %s not found.") % (patch, prod_info.name) + raise Exception(msg) + patches.append(rc.getValue()) prod_info.patches = patches + # Get the full paths of the environment scripts if product_has_env_script(prod_info): - env_script_path = prod_info.environ.env_script + env_script = str(prod_info.environ.env_script) # If only a filename, then search for the environment script # in the PRODUCTPATH/env_scripts - if os.path.basename(env_script_path) == env_script_path: - # Search in the PRODUCTPATH/env_scripts - env_script_path = UTS.find_file_in_lpath( - prod_info.environ.env_script, - config.PATHS.PRODUCTPATH, - "env_scripts") - if not env_script_path: - msg = _("Environment script %(1)s for %(2)s not found.\n") % \ - {"1" : env_script_path, "2" : prod_info.name} - raise Exception(msg) + if os.path.basename(env_script) == env_script: + # Search in the PRODUCTPATH/env_scripts + rc = UTS.find_file_in_lpath(env_script, config.PATHS.PRODUCTPATH, "env_scripts") + if not rc.isOk(): + msg = _("Environment script %s for %s not found.\n") % \ + (env_script, prod_info.name) + raise Exception(msg) + else: + env_script = rc.getValue() - prod_info.environ.env_script = env_script_path + prod_info.environ.env_script = env_script if with_install_dir: # The variable with_install_dir is at false only for internal use diff --git a/src/returnCode.py b/src/returnCode.py index ff0258a..7010ccc 100644 --- a/src/returnCode.py +++ b/src/returnCode.py @@ -36,28 +36,35 @@ _TIMEOUT_STATUS = "TIMEOUT" ##################################################### class ReturnCode(object): """ - assume simple return code for methods, with explanation as 'why' - obviously why is why it is not OK, - but also why is why it is OK (if you want). - and optionnaly contains a return value as self.getValue() + assume simple return code for methods, with explanation as 'why'. + Obviously why is 'why it is not OK', + but also why is 'why it is OK' (if you want). + Optionaly contains a return value as self.getValue() - Usage: - >> import returnCode as RCO - - >> aValue = doSomethingToReturn() - >> return RCO.ReturnCode("KO", "there is no problem here", aValue) - >> return RCO.ReturnCode("KO", "there is a problem here because etc", None) - >> return RCO.ReturnCode("TIMEOUT_STATUS", "too long here because etc") - >> return RCO.ReturnCode("NA", "not applicable here because etc") - - >> rc = doSomething() - >> print("short returnCode string", str(rc)) - >> print("long returnCode string with value", repr(rc)) - - >> rc1 = RCO.ReturnCode("OK", ...) - >> rc2 = RCO.ReturnCode("KO", ...) - >> rcFinal = rc1 + rc2 - >> print("long returnCode string with value", repr(rcFinal)) # KO! + | Usage: + | >> import returnCode as RCO + | + | >> aValue = doSomethingToReturn() + | >> return RCO.ReturnCode("KO", "there is no problem here", aValue) + | >> return RCO.ReturnCode("KO", "there is a problem here because etc", None) + | >> return RCO.ReturnCode("TIMEOUT_STATUS", "too long here because etc") + | >> return RCO.ReturnCode("NA", "not applicable here because etc") + | + | >> rc = doSomething() + | >> print("short returnCode string", str(rc)) + | >> print("long returnCode string with value", repr(rc)) + | + | >> rc1 = RCO.ReturnCode("OK", ...) + | >> rc2 = RCO.ReturnCode("KO", ...) + | >> rcFinal = rc1 + rc2 + | >> print("long returnCode string with value", repr(rcFinal)) # KO! + | + | >> rc = doSomething() + | >> if rc.isOk(): doSomethingAsOK() + | >> if not rc.isOk(): doSomethingAsKO() + | + | >> rc = doSomething().raiseIfKo() # raise Exception if KO + | >> doSomethingWithValue(rc.getValue()) # here i am sure that is OK """ OK_STATUS = _OK_STATUS @@ -67,7 +74,7 @@ class ReturnCode(object): KNOWNFAILURE_STATUS = _KNOWNFAILURE_STATUS TIMEOUT_STATUS = _TIMEOUT_STATUS - # integer for sys.exit(anInt) + # an integer for sys.exit(anInteger) # OKSYS and KOSYS seems equal on linux or windows OKSYS = 0 # OK KOSYS = 1 # KO @@ -171,6 +178,14 @@ class ReturnCode(object): return (self._status == self.OK_STATUS) def raiseIfKo(self): - """raise an exception with message why if not ok""" - if self.isOk(): return - raise Exception(self.getWhy()) + """ + raise an exception with message why if not ok, else return self. + This trick is to write usage + + | >> rc = doSomething().raiseIfKo() # raise Exception if KO + | >> doSomethingWithValue(rc.getValue()) # here i am sure that is OK + """ + if self.isOk(): + return self + else: + raise Exception(self.getWhy()) diff --git a/src/salomeTools.py b/src/salomeTools.py index 4ba8662..9408ae5 100755 --- a/src/salomeTools.py +++ b/src/salomeTools.py @@ -18,17 +18,25 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -This file is the main entry file to salomeTools -NO __main__ entry allowed, use 'sat' (in parent directory) +This file is the main API file for salomeTools + +| Warning: NO '__main__ ' call allowed, +| Use 'sat' (in parent directory) +| +| Usage: see file ../sat """ +_KOSYS = 1 # avoid import src + ######################################################################## # NO __main__ entry allowed, use sat ######################################################################## if __name__ == "__main__": - sys.stderr.write("\nERROR: 'salomeTools.py' is not main command entry for sat: use 'sat' instead.\n\n") - KOSYS = 1 # avoid import src - sys.exit(KOSYS) + msg = """ +ERROR: 'salomeTools.py' is not main command entry (CLI) for salomeTools. + Use 'sat' instead.\n\n""" + sys.stderr.write(msg) + sys.exit(_KOSYS) import os import sys diff --git a/src/test_module.py b/src/test_module.py index 709cf4e..7359de8 100755 --- a/src/test_module.py +++ b/src/test_module.py @@ -112,18 +112,14 @@ class Test: def prepare_testbase_from_dir(self, testbase_name, testbase_dir): self.logger.info(_("get test base from dir: %s\n") % UTS.label(testbase_dir)) if not os.access(testbase_dir, os.X_OK): - raise Exception( - _("testbase %(name)s (%(dir)s) does not exist ...\n") % \ - { 'name': testbase_name, 'dir': testbase_dir } ) + msg = _("testbase %s (%s) does not exist ...\n") % (testbase_name, testbase_dir ) + raise Exception(msg) self._copy_dir(testbase_dir, os.path.join(self.tmp_working_dir, 'BASES', testbase_name)) - def prepare_testbase_from_git(self, - testbase_name, - testbase_base, - testbase_tag): - self.logger.info( _("get test base '%s' with '%s' tag from git\n") % \ + def prepare_testbase_from_git(self, testbase_name, testbase_base, testbase_tag): + self.logger.info( _("get test base %s with %s tag from git\n") % \ (UTS.label(testbase_name), UTS.label(testbase_tag)) ) try: def set_signal(): # pragma: no cover @@ -158,14 +154,14 @@ class Test: stdout=self.logger.logTxtFile, stderr=subprocess.PIPE) if res != 0: - raise Exception(_("Error: unable to get test base " - "'%(name)s' from git '%(repo)s'.") % \ - { 'name': testbase_name, - 'repo': testbase_base }) + msg = _("Unable to get test base '%s' from git '%s'.") % \ + (testbase_name, testbase_base) + raise Exception(msg) except OSError: - self.logger.error(_("git is not installed. exiting...\n")) - sys.exit(0) + msg = _("git is not installed. Have to exit") + self.logger.critical(msg) + raise Exception(msg) def prepare_testbase_from_svn(self, user, testbase_name, testbase_base): self.logger.info(_("get test base '%s' from svn\n") % UTS.label(testbase_name)) @@ -203,13 +199,14 @@ class Test: env=env_appli.environ.environ,) if res != 0: - raise Exception( - _("ERROR: unable to get test base '%(name)s' from svn '%(repo)s'.") % \ - { 'name': testbase_name, 'repo': testbase_base } ) + msg = _("ERROR: unable to get test base '%s' from svn '%s'.") % \ + (testbase_name, testbase_base) + raise Exception(msg) except OSError: - self.logger.error(_("svn is not installed. exiting...\n")) - sys.exit(0) + msg = _("svn is not installed. Have to exit.") + self.logger.critical(msg) + raise Exception(msg) def prepare_testbase(self, test_base_name): """Configure tests base.""" diff --git a/src/utilsSat.py b/src/utilsSat.py index 3b3b107..54a7638 100644 --- a/src/utilsSat.py +++ b/src/utilsSat.py @@ -57,7 +57,9 @@ def ensure_path_exists(path): os.makedirs(path) def replace_in_file(file_in, str_in, str_out): - """Replace by in file + """ + Replace by in file . + save a file old version as file_in + '_old' :param file_in: (str) The file name :param str_in: (str) The string to search @@ -185,8 +187,8 @@ class Path: def find_file_in_lpath(file_name, lpath, additional_dir = ""): """ - Find in all the directories in lpath list the file - that has the same name as file_name. + Find the file that has the same name as file_name , + searching in directories listed in lpath. If it is found, return the full path of the file, else, return False. The additional_dir (optional) is the name of the directory to add to all paths in lpath. @@ -194,17 +196,21 @@ def find_file_in_lpath(file_name, lpath, additional_dir = ""): :param file_name: (str) The file name to search :param lpath: (list) The list of directories where to search :param additional_dir: (str) The name of the additional directory - :return: (str) The full path of the file or False if not found + :return: (ReturnCode) The full path of the file or False if not found """ + if len(lpath) < 1: + raise Exception("find file with no directories to search into") for directory in lpath: - dir_complete = os.path.join(directory, additional_dir) - if not os.path.isdir(directory) or not os.path.isdir(dir_complete): - continue - l_files = os.listdir(dir_complete) - for file_n in l_files: - if file_n == file_name: - return os.path.join(dir_complete, file_name) - return False + dir_complete = os.path.join(directory, additional_dir) + if not os.path.isdir(directory) or not os.path.isdir(dir_complete): + continue + l_files = os.listdir(dir_complete) + for file_n in l_files: + if file_n == file_name: + found = os.path.join(dir_complete, file_name) + return RCO.ReturnCode("OK", "file %s found" % file_name, found) + + return RCO.ReturnCode("KO", "file %s not found" % file_name) def handleRemoveReadonly(func, path, exc): excvalue = exc[1] @@ -329,10 +335,13 @@ def get_log_path(config): return log_dir_path def get_salome_version(config): + + import src.product as PROD # avoid cross import + if hasattr(config.APPLICATION, 'version_salome'): Version = config.APPLICATION.version_salome else: - KERNEL_info = product.get_product_config(config, "KERNEL") + KERNEL_info = PROD.get_product_config(config, "KERNEL") VERSION = os.path.join( KERNEL_info.install_dir, "bin", "salome", "VERSION" ) if not os.path.isfile(VERSION): diff --git a/test/test_022_returnCode.py b/test/test_022_returnCode.py index d16ddd9..4e20f43 100755 --- a/test/test_022_returnCode.py +++ b/test/test_022_returnCode.py @@ -40,6 +40,7 @@ class TestCase(unittest.TestCase): def test_010(self): rc = RC() + self.assertFalse(rc.isOk()) rrc = str(rc) DBG.write("test_010 str", rrc) self.assertIn("ND:", rrc) @@ -53,6 +54,7 @@ class TestCase(unittest.TestCase): def test_015(self): rc = RC("OK", "all is good") + self.assertTrue(rc.isOk()) rrc = str(rc) DBG.write("test_015 str", rrc) self.assertIn("OK:", rrc) @@ -65,6 +67,7 @@ class TestCase(unittest.TestCase): self.assertIn("Not set", rrc) aVal = "I am a value result" rc.setValue(aVal) + self.assertTrue(rc.isOk()) self.assertEqual(rc.getValue(), aVal) rrc = repr(rc) DBG.write("repr", rrc) @@ -94,12 +97,16 @@ class TestCase(unittest.TestCase): rc0 = RC("KO") aVal = "I am a value result" rc1 = RC("OK", "all is good1", aVal + "1") + self.assertTrue(rc1.isOk()) rc1.setStatus("KO") # change status raz why and value + self.assertFalse(rc1.isOk()) + print rc0 + print rc1 self.assertEqual(repr(rc0), repr(rc1)) rc1 = RC("OK", "all is good1", aVal + "1") rc2 = rc0 + rc1 + rc1 + rc0 + rc1 - DBG.write("test_020 repr", rc2, True) + DBG.write("test_025 repr", rc2, True) rrc = repr(rc2) self.assertIn("KO:", rrc)