-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrun_tests.py
executable file
·62 lines (50 loc) · 1.7 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
#!/usr/bin/env python
from __future__ import print_function
import os, sys, subprocess
class Object(object): pass
UNIT = '-u'
INTEGRATION = '-i'
actions = (UNIT, INTEGRATION)
action = sys.argv[1]
assert action in actions, "Expected one of %s" % (", ".join(actions),)
action_name = 'unit' if action == UNIT else 'integration'
args = sys.argv[2:]
cwd = os.getcwd()
kind = os.path.basename(cwd)
kinds = ('python', 'ocaml')
if kind not in kinds:
kind = None
root = os.path.abspath(os.path.dirname(__file__))
test_dir = os.path.join(root, 'test')
def add_to_env(name, val):
vals = os.environ.get(name, '').split(os.pathsep)
vals.insert(0, val)
os.environ[name] = os.pathsep.join(vals)
add_to_env('PYTHONPATH', os.path.join(os.path.dirname(__file__), 'python'))
try:
def run_nose(args):
args = args + ['-v']
args = ['--with-doctest', '-w', test_dir] + args
args = list(filter(None, os.environ.get('NOSE_ARGS', '').split())) + args
nose_exe = os.environ.get('NOSE_CMD', 'nosetests')
cmd = [nose_exe] + args
print('running: %r' % cmd)
subprocess.check_call(cmd)
subprocess.check_call(['make', '%s-test-pre' % action_name])
if action == INTEGRATION:
# run without adding to PATH
if kind is None:
exe = os.pathsep.join([os.path.join(cwd, kind, 'bin', 'gup') for kind in kinds])
else:
exe = os.path.join(cwd, 'bin', 'gup')
os.environ['GUP_EXE'] = exe
run_nose(args)
else:
assert action == UNIT
add_to_env('PATH', os.path.join(root, 'test/bin'))
if kind == 'ocaml':
subprocess.check_call(['./_build/default/test/test.exe', '-runner', 'sequential'] + args)
else:
add_to_env('PYTHONPATH', os.path.join(root, 'python'))
run_nose(args)
except subprocess.CalledProcessError: sys.exit(1)