From: Christian Van Wambeke Date: Fri, 19 Jan 2018 14:03:35 +0000 (+0100) Subject: fix AllTestLauncherSat.py and test_*: many errors yet X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=93d7e8862cbfc6fb781574ddb79213dc64fe3373;p=tools%2Fsat.git fix AllTestLauncherSat.py and test_*: many errors yet --- diff --git a/AllTestLauncherSat.py b/AllTestLauncherSat.py index d04f427..1a2be07 100755 --- a/AllTestLauncherSat.py +++ b/AllTestLauncherSat.py @@ -65,6 +65,9 @@ import pprint as PP #pretty print debug = False verboseImport = True +# get path to salomeTools sources +satdir = os.path.dirname(os.path.realpath(__file__)) + def errPrint(aStr): """to avoid write in html or xml file log message""" sys.stderr.write(aStr + '\n') @@ -173,11 +176,12 @@ def runOnArgs(args): del sys.path[0] done = False filesForTest[aFile] = (aImport, aModule) - except: + except Exception as e: if done: del sys.path[0] #attention of sys.path appends done = False - errPrint("ERROR: AllTestLauncher: import '%s'" % aFile) + errPrint("ERROR: AllTestLauncher: import '%s':" % aFile) + errPrint(" %s\n" % e) continue listfilesForTest = sorted(filesForTest.keys()) @@ -270,7 +274,7 @@ def getParser(): dir name with absolute or relative path stand for root directory of recursive searching unittest python files ''', - default='.', + default=satdir, metavar='dirPath' ) parser.add_argument( @@ -302,11 +306,15 @@ If name = 'stdout' then all-in-one xml output at 'sys.stdout'. For pipe redirect ################################################################### if __name__ == '__main__': + # Make the src & command package accessible from all code + sys.path.insert(0, satdir) + args = getParser().parse_args(sys.argv[1:]) debug = args.debug directory = os.path.realpath(args.rootPath) if debug: print("INFO: args:\n %s" % PP.pformat(args)) sys.path.insert(0, directory) #supposed to be root of a package + runOnArgs(args) del sys.path[0] diff --git a/commands/__init__.py b/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/commands/config.py b/commands/config.py index 2cab5c5..f1ec2b8 100644 --- a/commands/config.py +++ b/commands/config.py @@ -20,15 +20,10 @@ import os import platform import datetime import shutil -import gettext import sys import src -# internationalization -satdir = os.path.dirname(os.path.realpath(__file__)) -gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n')) - # Define all possible option for config command : sat config parser = src.options.Options() parser.add_option('v', 'value', 'string', 'value', diff --git a/commands/job.py b/commands/job.py index bb5c88d..4f6b891 100644 --- a/commands/job.py +++ b/commands/job.py @@ -19,7 +19,7 @@ import os import src -import salomeTools +import src.salomeTools # Define all possible option for the make command : sat make parser = src.options.Options() diff --git a/commands/jobs.py b/commands/jobs.py index 7c53d12..0516243 100644 --- a/commands/jobs.py +++ b/commands/jobs.py @@ -1852,7 +1852,7 @@ Use the --list option to get the possible files.""") % config_file traceback.print_tb(exc_traceback, file=fp) fp.seek(0) stack = fp.read() - logger.write("\nTRACEBACK: %s\n" % stack.replace('"',"'"), 1) + logger.write("\nTRACEBACK:\n%s\n" % stack.replace('"',"'"), 1) finally: res = 0 diff --git a/commands/patch.py b/commands/patch.py index 3f18442..280961f 100644 --- a/commands/patch.py +++ b/commands/patch.py @@ -20,7 +20,7 @@ import os import subprocess import src -import prepare +import commands.prepare # Define all possible option for patch command : sat patch parser = src.options.Options() diff --git a/commands/source.py b/commands/source.py index 448774d..973cfd1 100644 --- a/commands/source.py +++ b/commands/source.py @@ -20,7 +20,7 @@ import os import shutil import src -import prepare +import commands.prepare # Define all possible option for patch command : sat patch parser = src.options.Options() @@ -503,7 +503,7 @@ def run(args, runner, logger): logger.write("\n", 2, False) # Get the products list with products informations regarding the options - products_infos = prepare.get_products_list(options, runner.cfg, logger) + products_infos = commands.prepare.get_products_list(options, runner.cfg, logger) # Call to the function that gets all the sources good_result, results = get_all_product_sources(runner.cfg, diff --git a/salomeTools.py b/salomeTools.py deleted file mode 100755 index 219cc5c..0000000 --- a/salomeTools.py +++ /dev/null @@ -1,555 +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 -'''This file is the main entry file to salomeTools -''' - -# python imports -import os -import sys -import re -import tempfile -import imp -import types -import gettext -import traceback - -# salomeTools imports -import src - -# get path to salomeTools sources -satdir = os.path.dirname(os.path.realpath(__file__)) -cmdsdir = os.path.join(satdir, 'commands') - -# Make the src package accessible from all code -sys.path.append(satdir) -sys.path.append(cmdsdir) - -import config -import src.debug as DBG - -# load resources for internationalization -#es = gettext.translation('salomeTools', os.path.join(satdir, 'src', 'i18n')) -#es.install() -gettext.install('salomeTools', os.path.join(satdir, 'src', 'i18n')) - -# The possible hooks : -# pre is for hooks to be executed before commands -# post is for hooks to be executed after commands -C_PRE_HOOK = "pre" -C_POST_HOOK = "post" - -def find_command_list(dirPath): - ''' Parse files in dirPath that end with .py : it gives commands list - - :param dirPath str: The directory path where to search the commands - :return: cmd_list : the list containing the commands name - :rtype: list - ''' - cmd_list = [] - for item in os.listdir(dirPath): - if item.endswith('.py'): - cmd_list.append(item[:-len('.py')]) - return cmd_list - -# The list of valid salomeTools commands -#lCommand = ['config', 'compile', 'prepare'] -lCommand = find_command_list(cmdsdir) - -# Define all possible option for salomeTools command : sat