10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-09-27 03:51:01 +02:00
quantum_package/scripts/qp_test
2019-01-07 16:16:56 +01:00

81 lines
2.1 KiB
Python
Executable File

#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Runs all the possible tests using bats.
Usage:
qp_test [-av] [TEST]
Options:
-v verbose output
-a test all installed modules. Default is to test the current directory.
"""
import sys
import os
import subprocess
try:
from docopt import docopt
from qp_path import QP_SRC, QP_PLUGINS, QP_ROOT, QP_TESTS
except ImportError:
print "Please check if you have sourced the ${QP_ROOT}/quantum_package.rc"
print "(`source ${QP_ROOT}/quantum_package.rc`)"
sys.exit(1)
def main(arguments):
# Fetch all *.bats files
l_bats = []
def append_bats(dirname, filenames):
for f in filenames:
if f.endswith(".bats"):
number, _ = f.split('.',1)
l_bats.append( (int(number), os.path.join(dirname,f)) )
if arguments["TEST"]:
os.environ["TEST"] = arguments["TEST"]
if arguments["-a"]:
for (dirname, _, filenames) in os.walk(QP_SRC, followlinks=False) :
if "IRPF90_temp" not in dirname:
append_bats(dirname, filenames)
else:
for (dirname, _, filenames) in os.walk(os.getcwd(), followlinks=False) :
if "IRPF90_temp" not in dirname:
append_bats(dirname, filenames)
l_bats = [ y for x,y in sorted(l_bats) ]
# Execute tests
os.chdir(QP_TESTS)
for bats_file in l_bats:
print ""
print "-~-~-~-~-~-~"
print ""
print "Running tests for %s"%(bats_file)
print ""
if arguments["-v"]:
p = None
if arguments["TEST"]:
TEST="export TEST=%s\n"%arguments["TEST"]
else:
TEST=""
script = TEST+(subprocess.check_output(["python2", "bats_to_sh.py", bats_file]) )
try:
p = subprocess.check_call(script, shell=True, env=os.environ)
except:
if p: p.terminate()
else:
subprocess.check_call(["bats", bats_file], env=os.environ)
if __name__ == '__main__':
arguments = docopt(__doc__)
main(arguments)