From 8b959ec696b59ae1002dbc68ff53c387ce0f1b84 Mon Sep 17 00:00:00 2001 From: Anthony Scemama Date: Fri, 21 Dec 2018 16:34:04 +0100 Subject: [PATCH] Moved bats files and added qp_test. Need to change travis --- TODO | 2 - scripts/qp_test | 68 ++++++++++++++++++++++++ scripts/utility/qp_path.py | 1 + {tests/bats => src/fci}/fci.bats | 0 {tests/bats => src/hartree_fock}/hf.bats | 3 +- 5 files changed, 71 insertions(+), 3 deletions(-) create mode 100755 scripts/qp_test rename {tests/bats => src/fci}/fci.bats (100%) rename {tests/bats => src/hartree_fock}/hf.bats (93%) diff --git a/TODO b/TODO index cf4f7099..8356d545 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,3 @@ -* Virer cache compile - # qp_module * Mettre les fichiers de test dans le directory source diff --git a/scripts/qp_test b/scripts/qp_test new file mode 100755 index 00000000..ccab6083 --- /dev/null +++ b/scripts/qp_test @@ -0,0 +1,68 @@ +#!/usr/bin/env python2 +# -*- coding: utf-8 -*- + +""" +Runs all the possible tests using bats. + +Usage: + qp_test [-av] + +Options: + -v verbose output + -a test all installed modules. Default is to test the current directory. + +""" + +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`)" + print 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"): + l_bats.append( os.path.join(dirname,f) ) + + if arguments["-a"]: + for (dirname, _, filenames) in os.walk(QP_SRC, followlinks=False) : + append_bats(dirname, filenames) + else: + for (dirname, _, filenames) in os.walk(os.getcwd(), followlinks=False) : + append_bats(dirname, filenames) + print 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"]: + p1 = subprocess.Popen(["python2", "bats_to_sh.py", bats_file], \ + stdout=subprocess.PIPE) + p2 = subprocess.Popen(["bash"], stdin=p1.stdout) + _, _ = os.waitpid(p2.pid,0) + _, _ = os.waitpid(p1.pid,0) + else: + subprocess.check_call(["bats", bats_file]) + + + +if __name__ == '__main__': + arguments = docopt(__doc__) + main(arguments) + + diff --git a/scripts/utility/qp_path.py b/scripts/utility/qp_path.py index f8754465..ac53f118 100644 --- a/scripts/utility/qp_path.py +++ b/scripts/utility/qp_path.py @@ -14,3 +14,4 @@ else: QP_PLUGINS = os.path.join(QP_ROOT, "plugins") QP_EZFIO = os.environ["QP_EZFIO"] QP_OCAML = os.path.join(QP_ROOT, "ocaml") + QP_TESTS = os.path.join(QP_ROOT, "tests") diff --git a/tests/bats/fci.bats b/src/fci/fci.bats similarity index 100% rename from tests/bats/fci.bats rename to src/fci/fci.bats diff --git a/tests/bats/hf.bats b/src/hartree_fock/hf.bats similarity index 93% rename from tests/bats/hf.bats rename to src/hartree_fock/hf.bats index 5ef4ba56..893b9257 100644 --- a/tests/bats/hf.bats +++ b/src/hartree_fock/hf.bats @@ -4,6 +4,7 @@ source $QP_ROOT/tests/bats/common.bats.sh function run_init() { cp "${QP_ROOT}/tests/input/$1" . + rm -rf -- $3 qp_create_ezfio_from_xyz $1 -o $3 $2 qp_edit -c $3 } @@ -14,7 +15,7 @@ function run_HF() { test_exe scf || skip qp_edit -c $1 ezfio set_file $1 - ezfio set hartree_fock thresh_scf 1.e-10 + ezfio set scf_utils thresh_scf 1.e-10 qp_run scf $1 energy="$(ezfio get hartree_fock energy)" eq $energy $2 $thresh