From 4090372e27f86919964c6a73d566fed80dd709c1 Mon Sep 17 00:00:00 2001 From: Christian Van Wambeke Date: Thu, 13 Dec 2018 16:31:12 +0100 Subject: [PATCH] begin fix sat test --- commands/config.py | 11 +- commands/generate.py | 2 +- commands/log.py | 26 ++- commands/template.py | 4 +- commands/test.py | 97 +++++++---- .../PythonComponent/src/PYCMPGUI/PYCMPGUI.py | 2 +- src/architecture.py | 34 +++- src/fileEnviron.py | 2 +- src/fork.py | 75 ++++---- src/pyconf.py | 2 +- src/test/scriptTemplate.py | 36 +++- src/test_module.py | 163 +++++++++--------- src/xmlManager.py | 37 ++-- unittestpy/HTMLTestRunner.py | 2 +- 14 files changed, 296 insertions(+), 197 deletions(-) diff --git a/commands/config.py b/commands/config.py index 768a2f2..21f861e 100644 --- a/commands/config.py +++ b/commands/config.py @@ -17,11 +17,12 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +import sys import platform import datetime import shutil import gettext -import sys +import pprint as PP import src import src.debug as DBG @@ -223,8 +224,9 @@ class ConfigManager: # ===================================================================== # create VARS section - var = self._create_vars(application=application, command=command, - datadir=datadir) + var = self._create_vars(application=application, command=command, datadir=datadir) + print("create_vars:\n%s" % PP.pformat(var)) + # add VARS to config cfg.VARS = src.pyconf.Mapping(cfg) for variable in var: @@ -891,6 +893,9 @@ def description(): def run(args, runner, logger): '''method that is called when salomeTools is called with config parameter. ''' + import src.architecture as ARCH + print("get_infosys %s " % PP.pformat(ARCH.get_infosys())) + # Parse the options (options, args) = parser.parse_args(args) diff --git a/commands/generate.py b/commands/generate.py index f0d1175..a8d2dc9 100644 --- a/commands/generate.py +++ b/commands/generate.py @@ -271,7 +271,7 @@ def check_yacsgen(config, directory, logger): yacsgen_info = src.product.get_product_config(config, 'YACSGEN') yacsgen_dir = yacsgen_info.install_dir yacs_src = _("Using YACSGEN from application") - elif os.environ.has_key("YACSGEN_ROOT_DIR"): + elif "YACSGEN_ROOT_DIR" in os.environ: yacsgen_dir = os.getenv("YACSGEN_ROOT_DIR") yacs_src = _("Using YACSGEN from environment") diff --git a/commands/log.py b/commands/log.py index c903ad5..4255c44 100644 --- a/commands/log.py +++ b/commands/log.py @@ -34,20 +34,18 @@ import src # Define all possible option for log command : sat log parser = src.options.Options() -parser.add_option('t', 'terminal', 'boolean', 'terminal', "Optional: " - "Terminal log.") -parser.add_option('l', 'last', 'boolean', 'last', "Show the log of the last " - "Optional: launched command.") -parser.add_option('', 'last_terminal', 'boolean', 'last_terminal', "Show the " - "log of the last compilations" - "Optional: launched command.") -parser.add_option('f', 'full', 'boolean', 'full', "Optional: Show the logs of " - "ALL the launched commands.") -parser.add_option('c', 'clean', 'int', 'clean', "Optional: Erase the n most " - "ancient log files.") -parser.add_option('n', 'no_browser', 'boolean', 'no_browser', "Optional: Do not" - " launch the browser at the end of the command. Only update " - "the hat file.") +parser.add_option('t', 'terminal', 'boolean', 'terminal', + "Optional: Show the log (in terminal) of a command, with user choice.") +parser.add_option('l', 'last', 'boolean', 'last', + "Optional: Show the log (in browser) of the last launched command.") +parser.add_option('', 'last_terminal', 'boolean', 'last_terminal', + "Optional: Show the log (in terminal) of the last launched command.") +parser.add_option('f', 'full', 'boolean', 'full', + "Optional: Show the logs of ALL the launched commands.") +parser.add_option('c', 'clean', 'int', 'clean', + "Erase the n most ancient log files.") +parser.add_option('n', 'no_browser', 'boolean', 'no_browser', + "Optional: Do not launch the browser at the end of the command. Only update the hat file.") def get_last_log_file(logDir, notShownCommands): '''Used in case of last option. Get the last log command file path. diff --git a/commands/template.py b/commands/template.py index 604ce79..95419d0 100644 --- a/commands/template.py +++ b/commands/template.py @@ -81,7 +81,7 @@ class TParam: return len(val) > 0 and self.check_method(val) def get_dico_param(dico, key, default): - if dico.has_key(key): + if key in dico: return dico[key] return default @@ -178,7 +178,7 @@ class TemplateSettings: # ask user for values for p in self.parameters: tp = TParam(p, self.compo_name, dico) - if dico.has_key(tp.name): + if tp.name in dico: continue val = "" diff --git a/commands/test.py b/commands/test.py index 92d9e1c..8f3dd90 100644 --- a/commands/test.py +++ b/commands/test.py @@ -52,7 +52,8 @@ parser.add_option('s', 'session', 'list2', 'sessions', parser.add_option('', 'display', 'string', 'display', _("Optional: set the display where to launch SALOME.\n" "\tIf value is NO then option --show-desktop=0 will be used to launch SALOME.")) - +parser.add_option('', 'keep', 'boolean', 'keeptempdir', + _('Optional: keep temporary directory.')) def description(): '''method that is called when salomeTools is called with --help option. @@ -62,7 +63,7 @@ def description(): return _("The test command runs a test base on a SALOME installation.\n\n" "example:\nsat test SALOME-master --grid GEOM --session light") -def parse_option(args, config): +def parse_option_old(args, config): """ Parse the options and do some verifications about it :param args List: The list of arguments of the command @@ -76,8 +77,8 @@ def parse_option(args, config): options.launcher = "" elif not os.path.isabs(options.launcher): if not src.config_has_application(config): - raise src.SatException(_("An application is required to use a " - "relative path with option --appli")) + msg = _("An application is required to use a relative path with option --appli") + raise src.SatException(msg) options.launcher = os.path.join(config.APPLICATION.workdir, options.launcher) @@ -87,6 +88,39 @@ def parse_option(args, config): return (options, args) + +def parse_option(args, config): + """ Parse the options and do some verifications about it + + :param args List: The list of arguments of the command + :param config Config: The global configuration + :return: the options of the current command launch and the full arguments + :rtype: Tuple (options, args) + """ + (options, args) = parser.parse_args(args) + + if not options.launcher: + options.launcher = "" + return (options, args) + + if not os.path.isabs(options.launcher): + if not src.config_has_application(config): + msg = _("An application is required to use a relative path with option --appli") + raise src.SatException(msg) + else: + options.launcher = os.path.join(config.APPLICATION.workdir, options.launcher) + if not os.path.exists(options.launcher): + raise src.SatException(_("Launcher not found: %s") % options.launcher) + + # absolute path + launcher = os.path.realpath(os.path.expandvars(options.launcher)) + if os.path.exists(launcher): + options.launcher = launcher + return (options, args) + + raise src.SatException(_("Launcher not found: %s") % options.launcher) + + def ask_a_path(): """ """ @@ -166,8 +200,8 @@ def move_test_results(in_dir, what, out_dir, logger): os.makedirs(outtestbase) #logger.write(" copy testbase %s\n" % testbase, 5) - for grid_ in [m for m in os.listdir(intestbase) if os.path.isdir( - os.path.join(intestbase, m))]: + for grid_ in [m for m in os.listdir(intestbase) \ + if os.path.isdir(os.path.join(intestbase, m))]: # ignore source configuration directories if grid_[:4] == '.git' or grid_ == 'CVS': continue @@ -245,23 +279,20 @@ def create_test_report(config, first_time = False if not os.path.exists(xml_history_path): - if verbose: print("first_time as NOT existing '%s'" % xml_history_path) # cvw TODO + print("Log file creation %s" % xml_history_path) first_time = True root = etree.Element("salome") prod_node = etree.Element("product", name=application_name, build=xmlname) root.append(prod_node) else: - if verbose: print("NOT first_time as existing '%s'" % xml_history_path) # cvw TODO + print("Log file modification %s" % xml_history_path) root = etree.parse(xml_history_path).getroot() prod_node = root.find("product") - + + prod_node.attrib["history_file"] = os.path.basename(xml_history_path) prod_node.attrib["global_res"] = retcode - # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb - # de remontee de log des tests - #print "TRACES OP - test.py/create_test_report() : xml_history_path = '#%s#'" %xml_history_path - if withappli: if not first_time: for node in (prod_node.findall("version_to_download") + @@ -305,7 +336,7 @@ def create_test_report(config, tt = {} for test in config.TESTS: - if not tt.has_key(test.testbase): + if not test.testbase in tt: tt[test.testbase] = [test] else: tt[test.testbase].append(test) @@ -358,7 +389,7 @@ def create_test_report(config, mn.attrib["executed_last_time"] = "yes" - if not sessions.has_key("%s/%s" % (test.grid, test.session)): + if not "%s/%s" % (test.grid, test.session) in sessions: if first_time: tyn = add_simple_node(mn, "session") tyn.attrib['name'] = test.session @@ -517,12 +548,8 @@ def create_test_report(config, if not xmlname.endswith(".xml"): xmlname += ".xml" - src.xmlManager.write_report(os.path.join(dest_path, xmlname), - root, - "test.xsl") - src.xmlManager.write_report(xml_history_path, - root, - "test_history.xsl") + src.xmlManager.write_report(os.path.join(dest_path, xmlname), root, "test.xsl") + src.xmlManager.write_report(xml_history_path, root, "test_history.xsl") return src.OK_STATUS def generate_history_xml_path(config, test_base): @@ -636,15 +663,15 @@ def run(args, runner, logger): content = "\n".join(lines) # create hash from context information - dirname = datetime.datetime.now().strftime("%y%m%d_%H%M%S_") + sha1(content.encode()).hexdigest()[0:6] + # CVW TODO or not dirname = datetime.datetime.now().strftime("%y%m%d_%H%M%S_") + sha1(content.encode()).hexdigest()[0:8] + dirname = sha1(content.encode()).hexdigest()[0:8] # only 8 firsts probably good base_dir = os.path.join(tmp_dir, dirname) os.makedirs(base_dir) os.environ['TT_TMP_RESULT'] = base_dir # create env_info file - f = open(os.path.join(base_dir, 'env_info.py'), "w") - f.write(content) - f.close() + with open(os.path.join(base_dir, 'env_info.py'), "w") as f: + f.write(content) # create working dir and bases dir working_dir = os.path.join(base_dir, 'WORK') @@ -698,7 +725,7 @@ def run(args, runner, logger): log_dir = src.get_log_path(runner.cfg) out_dir = os.path.join(log_dir, "TEST") src.ensure_path_exists(out_dir) - name_xml_board = logger.logFileName.split(".")[0] + "board" + ".xml" + name_xml_board = logger.logFileName.split(".")[0] + "_board.xml" historic_xml_path = generate_history_xml_path(runner.cfg, test_base) create_test_report(runner.cfg, @@ -708,26 +735,22 @@ def run(args, runner, logger): xmlname = name_xml_board) xml_board_path = os.path.join(out_dir, name_xml_board) - # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb - # de remontee de log des tests - #print "TRACES OP - test.py/run() : historic_xml_path = '#%s#'" %historic_xml_path - #print "TRACES OP - test.py/run() : log_dir = '#%s#'" %log_dir - #print "TRACES OP - test.py/run() : name_xml_board = '#%s#'" %name_xml_board - logger.l_logFiles.append(xml_board_path) logger.add_link(os.path.join("TEST", name_xml_board), "board", retcode, "Click on the link to get the detailed test results") - logger.write("\nTests board is file %s\n" % xml_board_path, 1) + logger.write("\nTests board file %s\n" % xml_board_path, 1) # Add the historic files into the log files list of the command logger.l_logFiles.append(historic_xml_path) - - logger.write(_("Removing the temporary directory: " - "rm -rf %s\n" % test_runner.tmp_working_dir), 5) - if os.path.exists(test_runner.tmp_working_dir): + + if not options.keeptempdir: + logger.write("Removing the temporary directory: rm -rf %s\n" % test_runner.tmp_working_dir, 5) + if os.path.exists(test_runner.tmp_working_dir): shutil.rmtree(test_runner.tmp_working_dir) + else: + logger.write("NOT Removing the temporary directory: rm -rf %s\n" % test_runner.tmp_working_dir, 5) return retcode diff --git a/data/templates/PythonComponent/src/PYCMPGUI/PYCMPGUI.py b/data/templates/PythonComponent/src/PYCMPGUI/PYCMPGUI.py index f33ec81..2b31c81 100755 --- a/data/templates/PythonComponent/src/PYCMPGUI/PYCMPGUI.py +++ b/data/templates/PythonComponent/src/PYCMPGUI/PYCMPGUI.py @@ -87,7 +87,7 @@ def setDesktop( studyID ): global moduleDesktop, currentDesktop, objectsManager - if not moduleDesktop.has_key( studyID ): + if not studyID in moduleDesktop: moduleDesktop[studyID] = :sat:{PYCMP}Desktop( sgPyQt, sg ) objectsManager = Controller( moduleDesktop[studyID] ) moduleDesktop[studyID].setController( objectsManager ) diff --git a/src/architecture.py b/src/architecture.py index c2cd5ba..de8663d 100644 --- a/src/architecture.py +++ b/src/architecture.py @@ -37,7 +37,7 @@ def get_user(): ''' # In windows case, the USERNAME environment variable has to be set if is_windows(): - if not os.environ.has_key('USERNAME'): + if not 'USERNAME' in os.environ: raise Exception('USERNAME environment variable not set') return os.environ['USERNAME'] else: # linux @@ -93,6 +93,38 @@ def get_distribution(codes): return distrib +# Added by Lioka RAZAFINDRAZAKA +# and functions are used to get info from shell command +def run_shell(sh_cmd, pipe=True): + import subprocess + if pipe: popen = subprocess.Popen(sh_cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: popen = subprocess.Popen(sh_cmd, shell=True, close_fds=True) + out_put = popen.communicate() + return out_put[0], out_put[1], popen.returncode + +def get_infosys(): + import re, socket + osys = "" + version = "" + architecture = "" + osys_value = "Unknown" + os_dict = {"mandrivalinux":"MD", "centos":"CO", "RedHatEnterpriseServer":"CO", "RedHatEnterpriseWorkstation":"CO", "fedora":"FD", "ubuntu":"UB", "debian":"DB", "mageia":"MG",} + lsb_cmd = "lsb_release -ds" + output, errdata, return_code = run_shell(lsb_cmd) + regexp = r"(^[0-9]+([.]?[0-9]+)+)" + for an_item in output.replace('"','').split(): + if re.match(regexp, an_item) is not None and not version: + version = ".".join(an_item.split(".")[:2]) + else: + for sub_item in os_dict.keys(): + if sub_item == an_item.lower(): + osys = an_item + osys_value = os_dict[sub_item] + if version and osys: break + import platform + architecture = platform.architecture()[0][:2] + infosys = "_".join([osys,version,architecture,"bits",socket.gethostname(),osys_value+version]) + return version, infosys def get_distrib_version(distrib, codes): '''Gets the version of the distribution diff --git a/src/fileEnviron.py b/src/fileEnviron.py index 2fafeaf..5f6aeca 100644 --- a/src/fileEnviron.py +++ b/src/fileEnviron.py @@ -729,7 +729,7 @@ class ScreenEnviron(FileEnviron): src.printcolors.printcInfo(name), sign, value)) def is_defined(self, name): - return self.defined.has_key(name) + return name in self.defined def get(self, name): return "${%s}" % name diff --git a/src/fork.py b/src/fork.py index 6684fda..bfa5d7a 100644 --- a/src/fork.py +++ b/src/fork.py @@ -33,8 +33,7 @@ def show_progress(logger, top, delai, ss=""): :param delai int: the number max :param ss str: the string to display """ - logger.write("\r%s\r%s %s / %s " % ((" " * 30), ss, top, (delai - top)), 4, - False) + logger.write("\r%s\r%s timeout %s / %s stay %s s " % ((" " * 30), ss, top, delai, (delai - top)), 4, False) logger.flush() def write_back(logger, message, level): @@ -51,18 +50,19 @@ def write_back(logger, message, level): def launch_command(cmd, logger, cwd, args=[], log=None): if log: log = file(log, "a") - logger.write("launch: %s\n" % cmd, 5, screenOnly=True) for arg in args: cmd += " " + arg - # OP Add Windows case + logger.write("launch_command:\n%s\n" % cmd, 5, screenOnly=True) + + # Add Windows case if src.architecture.is_windows(): prs = subprocess.Popen(cmd, shell=True, stdout=log, stderr=subprocess.STDOUT, cwd=cwd) - pass + else: prs = subprocess.Popen(cmd, shell=True, @@ -70,8 +70,7 @@ def launch_command(cmd, logger, cwd, args=[], log=None): stderr=subprocess.STDOUT, cwd=cwd, executable='/bin/bash') - pass - # END OP + return prs # Launch a batch @@ -98,11 +97,12 @@ def batch(cmd, logger, cwd, args=[], log=None, delai=20, sommeil=1): write_back(logger, "batch: exit (%s)\n" % str(proc.returncode), 5) return (proc.returncode == 0), top + # Launch a salome process # ----------------------- def batch_salome(cmd, logger, cwd, args, getTmpDir, - pendant="SALOME_Session_Server", fin="killSalome.py", - log=None, delai=20, sommeil=1, delaiapp=0): + pendant="SALOME_Session_Server", fin="killSalome.py", + log=None, delai=20, sommeil=1, delaiapp=0): beginTime = time.time() launch_command(cmd, logger, cwd, args, log) @@ -110,48 +110,59 @@ def batch_salome(cmd, logger, cwd, args, getTmpDir, if delaiapp == 0: delaiapp = delai - # first launch salome (looking for .pidict file) + # first launch salome (looking for _pidict file) top = 0 found = False + foundSalome = "batch salome not seen" tmp_dir = getTmpDir() + # print("batch_salome %s %s / %s sommeil %s:\n%s" % (tmp_dir, delai, delaiapp, sommeil, cmd)) while (not found and top < delaiapp): if os.path.exists(tmp_dir): listFile = os.listdir(tmp_dir) + listFile = [f for f in listFile if f.endswith("_pidict")] + # print("listFile %s" % listFile) else: listFile = [] for file_name in listFile: - if file_name.endswith("pidict"): - # sometime we get a old file that will be removed by runSalome. - # So we test that we can read it. - currentTime = None + # sometime we get a old file that will be removed by runSalome. + # So we test that we can read it. + currentTime = None + try: + statinfo = os.stat(os.path.join(tmp_dir, file_name)) + currentTime = statinfo.st_mtime + except: + pass + + if currentTime and currentTime > beginTime: + found = True + pidictFile = file_name + + """ + # CVW avoid unsupported pickle protocol: 3 because pidict from python3 KERNEL/bin/salome/addToKillList.py try: - statinfo = os.stat(os.path.join(tmp_dir, file_name)) - currentTime = statinfo.st_mtime - except: pass - - if currentTime and currentTime > beginTime: - try: - file_ = open(os.path.join(tmp_dir, file_name), "r") + with open(os.path.join(tmp_dir, file_name), "r") as file_: process_ids = pickle.load(file_) - file_.close() - for process_id in process_ids: - for __, cmd in process_id.items(): - if cmd == [pendant]: - found = True - pidictFile = file_name - except: - file_.close() + # print("pidict %s" % process_ids) + for process_id in process_ids: + for __, cmd in process_id.items(): + if cmd == [pendant]: + foundSalome = "batch salome started" + pidictFile = file_name + except Exception as e: + foundSalome = "python version %s problem reading file: %s" % (sys.version, e) + pass + """ time.sleep(sommeil) top += 1 - show_progress(logger, top, delaiapp, "launching salome or appli:") + show_progress(logger, top, delaiapp, "launching salome or appli found=%s:" % found) # continue or not if found: - write_back(logger, "batch_salome: started\n", 5) + logger.write("\nbatch_salome: supposed started\n", 5) else: - logger.write("batch_salome: FAILED to launch salome or appli\n", 3) + logger.write("\nbatch_salome: seems FAILED to launch salome or appli\n" % foundSalome, 3) return False, -1 # salome launched run the script diff --git a/src/pyconf.py b/src/pyconf.py index 7f2838f..2a655ca 100644 --- a/src/pyconf.py +++ b/src/pyconf.py @@ -496,7 +496,7 @@ class Mapping(Container): #if name == "__class__": # return '' data = object.__getattribute__(self, "data") - useData = data.has_key(name) + useData = name in data if useData: rv = getattr(data, name) else: diff --git a/src/test/scriptTemplate.py b/src/test/scriptTemplate.py index 82e7959..0481ac1 100644 --- a/src/test/scriptTemplate.py +++ b/src/test/scriptTemplate.py @@ -37,23 +37,35 @@ __stderr__ = sys.stderr with open(r'${resultFile}', 'w') as exec_result: exec_result.write('Open\n') - + print("ignore: %s" % ignore) for test in listTest: + fileTest = os.path.join(outWay, test) + # print("test file: %s" % fileTest) # cvw TODO with open(os.path.join(outWay, test[:-3] + ".result.py"), "w") as pylog: with open(os.path.join(outWay, test[:-3] + ".out.py"), "w") as testout: my_tools.init() - sys.stdout = testout - sys.stderr = testout + print("here set sys.stdout") + sys.stdout = testout # cvw TODO + sys.stderr = testout # cvw TODO - pylog.write('#-*- coding:utf-8 -*-\n') + # pylog.write('#!/usr/bin/env python\n') exec_result.write("Run %s " % test) exec_result.flush() try: timeStart = THEBIGTIME.time() - execfile(os.path.join(outWay, test), globals(), locals()) + # cd ..print("begin... %s" % fileTest) + # execfile(fileTest, globals(), locals()) obsolete python3 + with open(fileTest) as f: + # compile associates the filename with the code object making debugging a little easier + code = compile(f.read(), fileTest, 'exec') + exec(code, globals(), locals()) + timeTest = THEBIGTIME.time() - timeStart + # print("...done %s" % fileTest) timeTest = THEBIGTIME.time() - timeStart except SatNotApplicableError as ex: + # print("here SatNotApplicableError") + # pylog.write("here SatNotApplicableError") status = "NA" reason = str(ex) exec_result.write("NA\n") @@ -62,9 +74,11 @@ with open(r'${resultFile}', 'w') as exec_result: pylog.write('time = "' + timeTest.__str__() + '"\n') pylog.write('callback = "%s"\n' % reason) except Exception as ex: + # print("here Exception") + # pylog.write("here Exception pylog\n") status = "KO" reason = "" - if ignore.has_key(test): + if test in ignore: status = "KF" reason = "Known Failure = %s\n\n" % ignore[test] exec_result.write("%s\n" % status) @@ -80,17 +94,23 @@ with open(r'${resultFile}', 'w') as exec_result: file=pylog) pylog.write('"""\n') else: + # print("here else") + # pylog.write("here else pylog") exec_result.write("OK\n") pylog.write('status = "OK"\n') pylog.write('time = "' + timeTest.__str__() + '"\n') pass + # print("here testout.flush") + testout.flush() # testout.close() - sys.stdout = __stdout__ - sys.stderr = __stderr__ + # print("here restore sys.stdout") + sys.stdout = __stdout__ # cvw TODO + sys.stderr = __stderr__ # cvw TODO my_tools.writeInFiles(pylog) pass + pylog.flush() # pylog.close() exec_result.write('Close\n') diff --git a/src/test_module.py b/src/test_module.py index 84aae72..c8a3e7a 100644 --- a/src/test_module.py +++ b/src/test_module.py @@ -322,40 +322,45 @@ class Test: if verbose: print("test script: '%s':\n'%s'\n" % (resfile, open(resfile, 'r').read())) - execfile(resfile, gdic, ldic) - - status = src.TIMEOUT_STATUS - if not has_timed_out: - status = src.KO_STATUS - - if ldic.has_key('status'): - status = ldic['status'] - - expected = [] - if status == src.KO_STATUS or status == src.OK_STATUS: - status, expected = self.search_known_errors(status, - self.currentgrid, - self.currentsession, - test) - - callback = "" - if ldic.has_key('callback'): - callback = ldic['callback'] - elif status == src.KO_STATUS: - callback = "CRASH" - if verbose: - print("--- CRASH ldic\n%s" % PP.pformat(ldic)) # cvw TODO - print("--- CRASH gdic\n%s" % PP.pformat(gdic)) - pass - - exec_time = -1 - if ldic.has_key('time'): - try: - exec_time = float(ldic['time']) - except: + try: + execfile(resfile, gdic, ldic) + + status = src.TIMEOUT_STATUS + if not has_timed_out: + status = src.KO_STATUS + + if 'status' in ldic: + status = ldic['status'] + + expected = [] + if status == src.KO_STATUS or status == src.OK_STATUS: + status, expected = self.search_known_errors(status, + self.currentgrid, + self.currentsession, + test) + + callback = "" + if ldic.has_key('callback'): + callback = ldic['callback'] + elif status == src.KO_STATUS: + callback = "CRASH" + if verbose: + print("--- CRASH ldic\n%s" % PP.pformat(ldic)) # cvw TODO + print("--- CRASH gdic\n%s" % PP.pformat(gdic)) pass - results[test] = [status, exec_time, callback, expected] + exec_time = -1 + if 'time' in ldic: + try: + exec_time = float(ldic['time']) + except: + pass + + results[test] = [status, exec_time, callback, expected] + + except: + results[test] = ["?", -1, "", []] + # results[test] = [src.O_STATUS, -1, open(resfile, 'r').read(), []] # check if .py file exists testfile = os.path.join(self.currentDir, @@ -389,22 +394,17 @@ class Test: # calling all the scripts of a single directory. def generate_script(self, listTest, script_path, ignoreList): # open template file - template_file = open(os.path.join(self.config.VARS.srcDir, - "test", - "scriptTemplate.py"), 'r') - template = string.Template(template_file.read()) + tFile = os.path.join(self.config.VARS.srcDir, "test", "scriptTemplate.py") + with open(tFile, 'r') as f: + template = string.Template(f.read()) # create substitution dictionary d = dict() d['resourcesWay'] = os.path.join(self.currentDir, 'RESSOURCES') d['tmpDir'] = os.path.join(self.tmp_working_dir, 'WORK') d['toolsWay'] = os.path.join(self.config.VARS.srcDir, "test") - d['sessionDir'] = os.path.join(self.currentDir, - self.currentgrid, - self.currentsession) - d['resultFile'] = os.path.join(self.tmp_working_dir, - 'WORK', - 'exec_result') + d['sessionDir'] = os.path.join(self.currentDir, self.currentgrid, self.currentsession) + d['resultFile'] = os.path.join(self.tmp_working_dir, 'WORK', 'exec_result') d['listTest'] = listTest d['sessionName'] = self.currentsession d['ignore'] = ignoreList @@ -416,8 +416,8 @@ class Test: f.write(contents) - # Find the getTmpDir function that gives access to *pidict file directory. - # (the *pidict file exists when SALOME is launched) + # Find the getTmpDir function that gives access to *_pidict file directory. + # (the *_pidict file exists when SALOME is launched) def get_tmp_dir(self): # Rare case where there is no KERNEL in grid list # (for example MED_STANDALONE) @@ -430,10 +430,9 @@ class Test: if 'KERNEL_ROOT_DIR' in os.environ: root_dir = os.environ['KERNEL_ROOT_DIR'] - if ('APPLICATION' in self.config - and 'KERNEL' in self.config.APPLICATION.products): - root_dir = src.product.get_product_config(self.config, - "KERNEL").install_dir + if ('APPLICATION' in self.config and + 'KERNEL' in self.config.APPLICATION.products): + root_dir = src.product.get_product_config(self.config, "KERNEL").install_dir # Case where there the appli option is called (with path to launcher) if len(self.launcher) > 0: @@ -443,21 +442,19 @@ class Test: launcherDir = os.path.dirname(self.launcher) if launcherName == 'runAppli': # Old application - cmd = ("for i in " + launcherDir + "/env.d/*.sh; do source ${i};" - " done ; echo $KERNEL_ROOT_DIR") + cmd = """ +for i in %s/env.d/*.sh; + do source ${i}; +done +echo $KERNEL_ROOT_DIR +""" % launcherDir else: # New application - cmd = ("echo -e 'import os\nprint os.environ[\"KERNEL_" + - "ROOT_DIR\"]' > tmpscript.py; %s shell" + - " tmpscript.py") % self.launcher - - # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb - # de remontee de log des tests - #root_dir = subprocess.Popen(cmd, - # stdout=subprocess.PIPE, - # shell=True, - # executable='/bin/bash').communicate()[0].split()[-1] - # OP Add Windows case + cmd = """ +echo -e 'import os\nprint(os.environ[\"KERNEL_ROOT_DIR\"])' > tmpscript.py +%s shell tmpscript.py +""" % self.launcher + if src.architecture.is_windows(): subproc_res = subprocess.Popen(cmd, stdout=subprocess.PIPE, @@ -469,33 +466,24 @@ class Test: shell=True, executable='/bin/bash').communicate() pass - #print "TRACES OP - test_module.py/Test.get_tmp_dir() subproc_res = " - #for resLine in subproc_res: - # print "- '#%s#'" %resLine root_dir = subproc_res[0].split()[-1] - - # OP 14/11/2017 Ajout de traces pour essayer de decouvrir le pb - # de remontee de log des tests - #print "TRACES OP - test_module.py/Test.get_tmp_dir() root_dir = '#%s#'" %root_dir # import grid salome_utils from KERNEL that gives # the right getTmpDir function - (file_, pathname, description) = imp.find_module("salome_utils", - [os.path.join(root_dir, - 'bin', - 'salome')]) + aPath = [os.path.join(root_dir, 'bin', 'salome')] + sal_uts = "salome_utils" + try: + (file_, pathname, description) = imp.find_module(sal_uts, aPath ) + except Exception: + msg = "inexisting %s.py in %s" % (sal_uts, aPath) + raise Exception(msg) + try: - grid = imp.load_module("salome_utils", - file_, - pathname, - description) + grid = imp.load_module(sal_uts, file_, pathname, description) return grid.getLogDir except: - grid = imp.load_module("salome_utils", - file_, - pathname, - description) + grid = imp.load_module(sal_uts, file_, pathname, description) return grid.getTmpDir finally: if file_: @@ -600,7 +588,7 @@ class Test: binSalome, binPython, killSalome = self.generate_launching_commands() if self.settings.has_key("run_with_grids") and \ - self.settings["run_with_grids"].has_key(sessionname): + sessionname in self.settings["run_with_grids"]: binSalome = (binSalome + " -m %s" % self.settings["run_with_grids"][sessionname]) logWay = os.path.join(self.tmp_working_dir, "WORK", "log_cxx") @@ -641,8 +629,7 @@ class Test: log=logWay, delaiapp=time_out_salome) - self.logger.write("status = %s, elapsed = %s\n" % (status, elapsed), - 5) + self.logger.write("status = %s, elapsed = %s\n" % (status, elapsed), 5) # create the test result to add in the config object test_info = src.pyconf.Mapping(self.config) @@ -726,7 +713,13 @@ class Test: tests = os.listdir(os.path.join(self.currentDir, self.currentgrid, self.currentsession)) - tests = filter(lambda l: l.endswith(".py"), tests) + # avoid result files of previous tests, if presents + # tests = filter(lambda l: l.endswith(".py"), tests) + tests = [t for t in tests if t.endswith(".py") \ + and not ( t.endswith(".out.py") or \ + t.endswith(".result.py") or \ + t.endswith("wrapperScript.py") \ + ) ] tests = sorted(tests, key=str.lower) # build list of known failures @@ -856,7 +849,7 @@ Existing grids are: self.run_grid_tests() def run_script(self, script_name): - if ('APPLICATION' in self.config and + if ('APPLICATION' in self.config and script_name in self.config.APPLICATION): script = self.config.APPLICATION[script_name] if len(script) == 0: diff --git a/src/xmlManager.py b/src/xmlManager.py index 60cebca..c4a0f6f 100644 --- a/src/xmlManager.py +++ b/src/xmlManager.py @@ -17,6 +17,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA import os +import shutil + try: # For python2 import sys reload(sys) @@ -27,6 +29,8 @@ except: import src from . import ElementTree as etree +verbose = False + class XmlLogFile(object): '''Class to manage writing in salomeTools xml log file ''' @@ -57,8 +61,7 @@ class XmlLogFile(object): f = open(log_file_path, 'w') f.write("\n") if stylesheet: - f.write("\n" % - stylesheet) + f.write("\n" % stylesheet) f.write(etree.tostring(self.xmlroot, encoding='utf-8')) f.close() except IOError: @@ -200,15 +203,29 @@ def write_report(filename, xmlroot, stylesheet): :param xmlroot etree.Element: the Etree element to write to the file :param stylesheet str: The stylesheet to add to the begin of the file """ - if not os.path.exists(os.path.dirname(filename)): - os.makedirs(os.path.dirname(filename)) - - f = open(filename, "w") - f.write("\n") + dirname = os.path.dirname(filename) + if not os.path.exists(dirname): + os.makedirs(dirname) if len(stylesheet) > 0: - f.write("\n" % stylesheet) - f.write(etree.tostring(xmlroot, encoding='utf-8')) - f.close() + styleName = stylesheet + else: + styleName = None + + with open(filename, "w") as f: + f.write("\n") + if styleName is not None: + f.write("\n" % styleName) + f.write(etree.tostring(xmlroot, encoding='utf-8')) + + # create fileStyle in dirname if not existing + if styleName is not None: + styleFile = os.path.join(dirname, styleName) + if not os.path.exists(styleFile): + # copy if from "salomeTools/src/xsl" + srcdir = os.path.dirname(src.__file__) + srcFile = os.path.join(srcdir, "xsl", styleName) + if verbose: print("write_report %s style %s" % (srcFile, styleFile)) + shutil.copy(srcFile, dirname) def escapeSequence(aStr): """ diff --git a/unittestpy/HTMLTestRunner.py b/unittestpy/HTMLTestRunner.py index 0439bf4..17ef2cd 100644 --- a/unittestpy/HTMLTestRunner.py +++ b/unittestpy/HTMLTestRunner.py @@ -639,7 +639,7 @@ class HTMLTestRunner(Template_mixin): classes = [] for n,t,o,e in result_list: cls = t.__class__ - if not rmap.has_key(cls): + if not cls in rmap: rmap[cls] = [] classes.append(cls) rmap[cls].append((n,t,o,e)) -- 2.30.2