From: Gbkng Date: Wed, 14 Feb 2024 19:33:38 +0000 (+0100) Subject: feat(test): simplify initializeTest X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=788f9e5a0fcd6100a8e6622037b1b51f98c750dd;p=tools%2Fsat.git feat(test): simplify initializeTest --- diff --git a/test/initializeTest.py b/test/initializeTest.py index a54f6dd..9b6a842 100755 --- a/test/initializeTest.py +++ b/test/initializeTest.py @@ -1,65 +1,20 @@ -#!/usr/bin/env python -# -*- coding:utf-8 -*- - -# Copyright (C) 2010-2018 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 - - -"""\ -initialize PATH etc... for salomeTools unittest test files -""" +import os +import sys +import pprint as pp """ -https://docs.python.org/2/library/os.html -os.environ mapping is captured the first time the os module is imported, -typically during Python startup as part of processing site.py. -Changes to the environment made after this time are not reflected -in os.environ, except for changes made by modifying os.environ directly. - -On some platforms, including FreeBSD and Mac OS X, -setting environ may cause memory leaks. +initialize PATH etc... for salomeTools unittest test files """ -import os -import sys -import pprint as PP - -# get path to salomeTools sources directory parent satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) -# sys.stderr.write("INFO : initializeTest needs '%s' in sys.path:\n%s\n" % (satdir, PP.pformat(sys.path))) - if satdir not in sys.path: - # get path to salomeTools sources FIRST as prepend - # Make the src & commands package accessible from all test code + # prepend path to sat sources first + # make the 'src' & 'commands' packages accessible for all the tests sys.path.insert(0, satdir) sys.stderr.write( - """\ -WARNING : sys.path not set for salomeTools, fixed for you: - sys.path prepend '%s' - sys.path:\n%s\n""" - % (satdir, PP.pformat(sys.path)) - ) - # os.environ PATH is not set... - # supposedly useful only for subprocess launch from sat - # see https://docs.python.org/2/library/os.html - # On some platforms, including FreeBSD and Mac OS X, - # setting environ may cause memory leaks. - # sys.stderr.write("os.environ PATH:\n%s\n" % PP.pformat(os.environ["PATH"].split(":"))) - sys.stderr.write( - "INFO : to fix this message type:\n 'export PYTHONPATH=%s:${PYTHONPATH}'\n" - % satdir + f"warning: sat paths not detected in sys.path. Set automatically:\n\ + sys.path prepend '{satdir}'\n\ + sys.path:\n{pp.pformat(sys.path)}\n\ + You can set the path yourself with:\n 'export PYTHONPATH={satdir}:${{PYTHONPATH}}'\n" )