forked from vstinner/pysandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
75 lines (65 loc) · 2 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
from sandbox import HAVE_CSANDBOX
from sys import version_info
from sandbox.test import SkipTest, createSandboxConfig
from sandbox.test.tools import getTests
from sandbox.version import VERSION
def parseOptions():
from optparse import OptionParser
parser = OptionParser(usage="%prog [options]")
parser.add_option("--raise",
help="Don't catch exception",
dest="raise_exception",
action="store_true")
parser.add_option("--debug",
help="Enable debug mode (enable stdout and stderr features)",
action="store_true")
parser.add_option("-k", "--keyword",
help="Only execute tests with name containing KEYWORD",
type='str')
options, argv = parser.parse_args()
if argv:
parser.print_help()
exit(1)
return options
def main():
global createSandboxConfig
options = parseOptions()
createSandboxConfig.debug = options.debug
print("Run the test suite on pysandbox %s with Python %s.%s"
% (VERSION, version_info[0], version_info[1]))
if not HAVE_CSANDBOX:
print("WARNING: _sandbox module is missing")
print
# Get all tests
all_tests = getTests(globals(), options.keyword)
# Run tests
nerror = 0
if version_info < (2, 6):
base_exception = Exception
else:
base_exception = BaseException
for func in all_tests:
name = '%s.%s()' % (func.__module__.split('.')[-1], func.__name__)
try:
func()
except SkipTest, skip:
print("%s: skipped (%s)" % (name, skip))
except base_exception, err:
nerror += 1
print("%s: FAILED! %r" % (name, err))
if options.raise_exception:
raise
else:
print "%s: ok" % name
# Exit
from sys import exit
print
if nerror:
print "%s ERRORS!" % nerror
exit(1)
else:
print "%s tests succeed" % len(all_tests)
exit(0)
if __name__ == "__main__":
main()