-
Notifications
You must be signed in to change notification settings - Fork 19
/
run_tests.py
executable file
·128 lines (114 loc) · 4.11 KB
/
run_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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
"""
Driver script for testing polytope package. Try calling it with "-h" flag.
This script was originally copied from one by the same name in
TuLiP (https://tulip-control.org).
"""
# import imp # inline
# import importlib # inline
import sys
import os.path
import nose
if __name__ == "__main__":
if ("-h" in sys.argv) or ("--help" in sys.argv):
print("""Usage: run_tests.py [OPTIONS...] [[-]TESTFILES...]
TESTFILES... is space-separated list of test file names, where the suffix
"_test.py" is added to each given name. E.g.,
run_tests.py gr1cint
causes the gr1cint_test.py file to be used and no others. If no arguments
are given, then default is to run all tests. If TESTFILES... each have a
prefix of "-", then all tests *except* those listed will be run. Besides
what is below, OPTIONS... are passed on to nose.
--fast exclude tests that are marked as slow
--cover generate a coverage report
--outofsource import polytope from outside the current directory
--where=DIR search for tests in directory DIR; default is "tests"
(this is exactly the "-w" or "--where" option of nose)""")
exit(1)
if "--fast" in sys.argv:
skip_slow = True
sys.argv.remove("--fast")
else:
skip_slow = False
if "--cover" in sys.argv:
measure_coverage = True
sys.argv.remove("--cover")
else:
measure_coverage = False
if "--outofsource" in sys.argv:
require_nonlocaldir_polytope = True
sys.argv.remove("--outofsource")
else:
require_nonlocaldir_polytope = False
# Try to find test directory among command-line arguments
given_tests_dir = False
for i in range(len(sys.argv[1:])):
if sys.argv[i+1] == "-w":
given_tests_dir = True
tests_dir = sys.argv[i+2]
break
if sys.argv[i+1].startswith("--where="):
given_tests_dir = True
tests_dir = sys.argv[i+1][len("--where="):]
break
if not given_tests_dir:
tests_dir = "tests"
if require_nonlocaldir_polytope:
# Scrub local directory from search path for modules
import os
try:
while True:
sys.path.remove("")
except ValueError:
pass
try:
while True:
sys.path.remove(os.path.abspath(os.curdir))
except ValueError:
pass
try:
if sys.version_info.major == 2:
import imp
modtuple = imp.find_module("polytope", sys.path)
imp.load_module("polytope", *modtuple)
else:
import importlib
importlib.import_module('polytope')
except ImportError:
if require_nonlocaldir_polytope:
raise ImportError(
"polytope package not found, "
"besides in the local directory")
else:
raise
argv = ["nosetests"]
if skip_slow:
argv.append("--attr=!slow")
if measure_coverage:
argv.extend([
"--with-coverage",
"--cover-html",
"--cover-package=polytope"])
testfiles = []
excludefiles = []
for basename in sys.argv[1:]: # Only add extant file names
if os.path.exists(os.path.join(tests_dir, basename+"_test.py")):
testfiles.append(basename+"_test.py")
elif basename[0] == "-":
if os.path.exists(
os.path.join(tests_dir, basename[1:]+"_test.py")):
excludefiles.append(basename[1:]+"_test.py")
else:
argv.append(basename)
else:
argv.append(basename)
if len(testfiles) > 0 and len(excludefiles) > 0:
print("You can specify files to exclude or include, but not both.")
print('Try calling it with "-h" flag.')
exit(1)
if len(excludefiles) > 0:
argv.append("--exclude="+"|".join(excludefiles))
argv.extend(testfiles)
if not given_tests_dir:
argv += ["--where="+tests_dir]
nose.main(argv=argv+["--verbosity=3", "--exe"])