Enable BytesWarnings.
[portage.git] / pym / portage / tests / runTests
1 #!/usr/bin/python -bbWd
2 # runTests.py -- Portage Unit Test Functionality
3 # Copyright 2006-2014 Gentoo Foundation
4 # Distributed under the terms of the GNU General Public License v2
5
6 import os, sys
7 import os.path as osp
8 import grp
9 import platform
10 import pwd
11 import signal
12
13 def debug_signal(signum, frame):
14         import pdb
15         pdb.set_trace()
16
17 if platform.python_implementation() == 'Jython':
18         debug_signum = signal.SIGUSR2 # bug #424259
19 else:
20         debug_signum = signal.SIGUSR1
21
22 signal.signal(debug_signum, debug_signal)
23
24 # Pretend that the current user's uid/gid are the 'portage' uid/gid,
25 # so things go smoothly regardless of the current user and global
26 # user/group configuration.
27 os.environ["PORTAGE_USERNAME"] = pwd.getpwuid(os.getuid()).pw_name
28 os.environ["PORTAGE_GRPNAME"] = grp.getgrgid(os.getgid()).gr_name
29
30 # Insert our parent dir so we can do shiny import "tests"
31 # This line courtesy of Marienz and Pkgcore ;)
32 sys.path.insert(0, osp.dirname(osp.dirname(osp.dirname(osp.realpath(__file__)))))
33
34 import portage
35 portage._internal_caller = True
36
37 # Ensure that we don't instantiate portage.settings, so that tests should
38 # work the same regardless of global configuration file state/existence.
39 portage._disable_legacy_globals()
40
41 if os.environ.get('NOCOLOR') in ('yes', 'true'):
42         portage.output.nocolor()
43
44 import portage.tests as tests
45 from portage.const import PORTAGE_BIN_PATH
46 path = os.environ.get("PATH", "").split(":")
47 path = [x for x in path if x]
48
49 insert_bin_path = True
50 try:
51         insert_bin_path = not path or \
52                 not os.path.samefile(path[0], PORTAGE_BIN_PATH)
53 except OSError:
54         pass
55
56 if insert_bin_path:
57         path.insert(0, PORTAGE_BIN_PATH)
58         os.environ["PATH"] = ":".join(path)
59
60 if __name__ == "__main__":
61         sys.exit(tests.main())