-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtests.py
executable file
·106 lines (100 loc) · 3.98 KB
/
runtests.py
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/env python
#Main program
import sys
def usage():
print 'Usage: runtests.py [-h] [-V] [--list] [--colors] [-g pdfname] [-H -T] conffile inputfile referencefile'
print ' Performs statistical tests for distributions contained in inputfile'
print ' tests are configured in conffile'
print ' conffile : configuration file'
print ' inputfile : input file containing distributions. If filename contains the the * character merge all files'
print ' matching name with hadd utility. Note that you may need to escape \* the charatecter in shells.'
print ' referencefile (optional) : reference file name that overwrites the one contained in the conf file'
print ' -h : this help'
print ' -v : verbose'
print ' -V : very verbose'
print ' -g : produce pdf with plos'
print ' --list : list all available tests'
print ' --colors : use ANSI colors for output results table'
print ''
print ' Example: runtests.py testconf.qa test.root'
print ' See content of example directory for an example of a configuration file'
def printList():
from Tests import _testsMap
print 'Known Tests:'
for k,v in _testsMap.iteritems():
print "Test: %s"%k
print v.__doc__
def run( argv = sys.argv ):
from Interface import runROOT
colors = False #By default use ANSI colors for output
if len(argv)>=1:
import getopt
try:
opts,args = getopt.getopt( argv ,"hvVTg:H",["list","colors"])
except getopt.GetoptError,err:
sys.stderr.write( str(err) )
usage()
sys.exit(2)
#t doplots = "report.pdf"
doplots = None
input = "HISTOS"
for op,ar in opts:
# print("OP %s AR %s"%(op,ar))
if op == '-h':
usage()
sys.exit(0)
elif op == '-v':
from Interface import _logger
_logger.setLevel('INFO')
elif op == '-V':
from Interface import _logger
_logger.setLevel('DEBUG')
elif op == '--list':
printList()
sys.exit(0)
elif op == "--colors":
colors = True
elif op == '-g':
doplots=ar
elif op == '-T':
input = "TEXT"
elif op == '-H':
input = "HISTOS"
if len(args)>=2:
inputfile=args[1]
if '*' in args[1]:
print 'Merging multiple input files'
from glob import glob
files=glob(args[1])
import subprocess
import tempfile
(fd,filename)=tempfile.mkstemp('.root')
subprocess.call(['hadd','-f',filename,]+files)
inputfile=filename
try:
if len(args)>=3:
if input == "TEXT" :
errcode = runROOT( args[0] ,inputfile , doPlots = None , doText = True , doHistos = False , doUnBinned = False , defaultReferenceFile = args[2] )
else :
errcode = runROOT( args[0], inputfile , doPlots = doplots , doText = False , defaultReferenceFile = args[2] , useColorsForOutput = colors)
else:
if input == "TEXT" :
sys.stderr.write("Error: NO REFERENCE FILE %s\n")
sys.exit(1)
else:
errcode = runROOT( args[0] , inputfile , doPlots = doplots , useColorsForOutput = colors)
except Exception,e:
sys.stderr.write("Error: %s\n"%e)
sys.exit(1)
else:
usage()
sys.exit(0)
else:
usage()
sys.exit(0)
if errcode > 0:
sys.stderr.write( "Number of FAILED tests: %d\n"%errcode)
sys.exit(1)
sys.exit( 0 )
if __name__ == "__main__":
run( sys.argv[1:])