9
1
mirror of https://github.com/QuantumPackage/qp2.git synced 2024-10-31 18:53:38 +01:00
qp2/bin/qp_test

80 lines
2.1 KiB
Plaintext
Raw Normal View History

2020-03-17 16:39:43 +01:00
#!/usr/bin/env python3
2019-01-25 11:39:31 +01:00
# -*- 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_TESTS
except ImportError:
2020-03-17 16:39:43 +01:00
print("Please check if you have sourced the ${QP_ROOT}/quantum_package.rc")
print("(`source ${QP_ROOT}/quantum_package.rc`)")
2019-01-25 11:39:31 +01:00
sys.exit(1)
def main(arguments):
"""Main function"""
# 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):
2023-04-14 16:35:06 +02:00
if "IRPF90_temp" not in dirname and "external" not in dirname:
2019-01-25 11:39:31 +01:00
append_bats(dirname, filenames)
l_bats = [y for _, y in sorted(l_bats)]
# Execute tests
os.chdir(QP_TESTS)
for bats_file in l_bats:
2020-03-17 16:39:43 +01:00
print("")
print("-~-~-~-~-~-~")
print("")
print("Running tests for %s"%(bats_file))
print("")
2019-01-25 11:39:31 +01:00
if arguments["-v"]:
if arguments["TEST"]:
test = "export TEST=%s ; "%arguments["TEST"]
else:
test = ""
2023-02-06 13:42:20 +01:00
os.system(test+" python3 bats_to_sh.py "+bats_file+
2019-01-25 11:39:31 +01:00
"| bash")
else:
2023-04-14 16:35:06 +02:00
# print(" ".join(["bats", "--verbose-run", "--trace", bats_file]))
2023-02-06 13:42:20 +01:00
subprocess.check_call(["bats", "--verbose-run", "--trace", bats_file], env=os.environ)
2019-01-25 11:39:31 +01:00
if __name__ == '__main__':
ARGS = docopt(__doc__)
main(ARGS)