Salome HOME
evite la construction de l'environnement launch, saus pour la commande sat check
[tools/sat.git] / test / initializeTest.py
1 #!/usr/bin/env python
2 #-*- coding:utf-8 -*-
3
4 #  Copyright (C) 2010-2018  CEA/DEN
5 #
6 #  This library is free software; you can redistribute it and/or
7 #  modify it under the terms of the GNU Lesser General Public
8 #  License as published by the Free Software Foundation; either
9 #  version 2.1 of the License.
10 #
11 #  This library is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 #  Lesser General Public License for more details.
15 #
16 #  You should have received a copy of the GNU Lesser General Public
17 #  License along with this library; if not, write to the Free Software
18 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19
20
21 """\
22 initialize PATH etc... for salomeTools unittest test files
23 """
24
25 """
26 https://docs.python.org/2/library/os.html
27 os.environ mapping is captured the first time the os module is imported, 
28 typically during Python startup as part of processing site.py. 
29 Changes to the environment made after this time are not reflected 
30 in os.environ, except for changes made by modifying os.environ directly.
31
32 On some platforms, including FreeBSD and Mac OS X, 
33 setting environ may cause memory leaks.
34 """
35
36 import os
37 import sys
38 import pprint as PP
39
40 # get path to salomeTools sources directory parent
41 satdir = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
42
43 # sys.stderr.write("INFO    : initializeTest needs '%s' in sys.path:\n%s\n" % (satdir, PP.pformat(sys.path)))
44
45 if satdir not in sys.path:
46   # get path to salomeTools sources FIRST as prepend
47   # Make the src & commands package accessible from all test code
48   sys.path.insert(0, satdir)
49   sys.stderr.write("""\
50 WARNING : sys.path not set for salomeTools, fixed for you:
51           sys.path prepend '%s'
52           sys.path:\n%s\n""" % (satdir, PP.pformat(sys.path)))
53   # os.environ PATH is not set...
54   # supposedly useful only for subprocess launch from sat
55   # see https://docs.python.org/2/library/os.html
56   # On some platforms, including FreeBSD and Mac OS X, 
57   # setting environ may cause memory leaks.
58   # sys.stderr.write("os.environ PATH:\n%s\n" % PP.pformat(os.environ["PATH"].split(":")))
59   sys.stderr.write("INFO    : to fix this message type:\n  'export PYTHONPATH=%s:${PYTHONPATH}'\n" % satdir)
60   
61