#!/usr/bin/env python3
"""
The km3test CLI interface
Usage:
km3test [options] [FILENAME]
km3test (-h | --help)
km3test --version
Options:
FILENAME Path to the file to be checked [optional if -c is set], can contain parameters
-t TYPE Name of the test to be performed if standard test
-c CONF Path to configuration file
-p PARAMS Path to file holding parameters if filename contains parameters
-o OUTFILE Path for the file holding the tabulated results
--save_all save all tests and results for reuse ("km3tests.pkl"), default: False
-h --help Show this screen.
Examples:
km3test -t filechecks_hasevents myfile.root # perform standard file check on file myfile.root
km3test -c myconfig.yml # perform check defined in myconfig.yml on files defined in the same file
# csv-table with column RUNNUMBER to check all files matching the file pattern:
km3test -p myrunlist.csv -o myresults.csv /where/files/are/filename_{RUNNUMBER}.root
"""
import km3test
from km3test.configure import TestManager
from docopt import docopt
[docs]def main():
args = docopt(__doc__, version=km3test.version)
filename = False
try:
filename = args["FILENAME"]
except:
if not args["-c"] and not filename:
print ("Did not find an input file")
return
localconf = {"tests": ["filechecks_hasevents"]}
if not args["-c"]:
localconf.setdefault("filepath", filename)
if args["-p"]:
localconf.setdefault("parameters", args["-p"])
if args["-t"]:
localconf["tests"] = [args["-t"]]
if args["-t"]:
if args["-c"]:
print ("You defined standard and custom setting. Will choose standard.")
manager = TestManager()
if args["-c"]:
manager.read_configfile(args["-c"])
else:
manager.add_input("clifile", localconf)
if args["-o"]:
manager.add_report("clitable",{"datatype": "table", "outfilepath": args["-o"]})
manager.create()
manager.run()
manager.report()
if args["--save_all"]:
manager.save_all("km3tests.pkl")
if manager.outputs["reports"].return_bool():
return "All tests passed"
else:
return "Some tests failed"