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
|
#!/usr/bin/python
import getopt
import os
import platform
import subprocess
import sys
components = ['db', 'http', 'script']
root = os.path.dirname(__file__)
report_path = None
def usage():
print "Usage: run.py [options]"
# parse options
try:
opts, args = getopt.getopt(sys.argv[1:], 'hvx:')
except getopt.GetoptError, err:
print err
usage()
sys.exit(2)
for opt, optarg in opts:
if opt == '-h':
usage()
sys.exit()
elif opt == '-v':
os.environ['QDJANGO_DB_DEBUG'] = '1'
elif opt == '-x':
report_path = optarg
if not os.path.exists(report_path):
os.mkdir(report_path)
# set library path
path = []
for component in components:
path.append(os.path.join(root, '..', 'src', component))
if platform.system() == 'Darwin':
os.environ['DYLD_LIBRARY_PATH'] = ':'.join(path)
else:
os.environ['LD_LIBRARY_PATH'] = ':'.join(path)
# run tests
failed = False
for component in components:
component_path = os.path.join(root, component)
for test in os.listdir(component_path):
test_path = os.path.join(component_path, test)
if os.path.isdir(test_path):
prog = os.path.join(test_path, 'tst_' + test)
if not os.path.exists(prog):
continue
cmd = [ prog ]
if report_path:
cmd += ['-xunitxml', '-o', os.path.join(report_path, test + '.xml') ]
try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError:
failed = True
# check for failure
if failed:
sys.exit(1)
|