10 from numpy
import linalg
18 __float_tol = Common.float_tolerance
20 def run_test_group(test_results, list_of_functions, list_of_args, alignment=40):
21 for i
in range(len(list_of_functions)):
22 run_test(test_results, list_of_functions[i], list_of_args[i])
24 def run_test(test_results, function, args, alignment=40):
26 test_name = function.__name__
27 test_name +=
' '*(alignment - len(test_name))
29 test_out = str(function(*args))
31 print 'Unhandled exception in test',function.__name__
32 sys.excepthook(*sys.exc_info())
35 sys.excepthook(*sys.exc_info())
37 test_results.append(test_name+test_out)
43 for line
in test_results:
44 if verbose_bool:
print line
45 if string.find(line,
'fail') >-1: fails +=1
46 elif string.find(line,
'False')>-1: fails +=1
47 elif string.find(line,
'pass') >-1: passes+=1
48 elif string.find(line,
'True') >-1: passes+=1
49 elif string.find(line,
'None') >-1: warns +=1
50 elif string.find(line,
'warn') < 0: warns +=1
52 if string.find(line,
'warn')>-1: warns +=1
54 return (passes, fails, warns)
57 def test_root_hist(hist, name, x_label, y_label, xmin, xmax, ymin, ymax, line_color, line_style, line_width, fill_color, title):
58 minmax_hist = [hist.GetXaxis().GetXmin(), hist.GetXaxis().GetXmax(), hist.GetYaxis().GetXmin(), hist.GetYaxis().GetXmax()]
59 minmax_user = [xmin, xmax, ymin, ymax]
61 if abs(minmax_hist[i]-minmax_user[i])>Common.float_tolerance:
62 print 'test_root_hist failed on minmax',i,
'with expected',minmax_user[i],
'actual',minmax_hist[i]
66 testpass = hist.GetXaxis().GetTitle()==x_label
and hist.GetYaxis().GetTitle()==y_label
and hist.GetTitle()==title
68 testpass &= hist.GetLineColor()==line_color
and hist.GetLineStyle()==line_style
and hist.GetFillColor()==fill_color
70 testpass &= hist.GetLineStyle()==line_style
and hist.GetFillColor()==fill_color
74 def test_root_canvas(canvas, name, title, bg_color, highlight_color, border_mode, frame_color):
76 testpass &= canvas.GetName().find(name) > -1
77 testpass &= canvas.GetTitle() == title
78 testpass &= canvas.GetFillColor() == bg_color
79 testpass &= canvas.GetBorderMode() == border_mode
80 testpass &= canvas.GetFrameFillColor() == frame_color
83 def test_root_canvas(canvas, name, title, bg_color, highlight_color, border_mode, frame_color):
85 testpass &= canvas.GetName().find(name) > -1
86 testpass &= canvas.GetTitle() == title
87 testpass &= canvas.GetFillColor() == bg_color
88 testpass &= canvas.GetBorderMode() == border_mode
89 testpass &= canvas.GetFrameFillColor() == frame_color
93 def test_root_graph(graph, name_string, x_list, y_list, line_color, line_style, line_width, fill_color):
95 testpass &= graph.GetN()==len(x_list)
98 for i
in range( len(x_list) ): testpass &= abs(x[i]-x_list[i])<__float_tol
and abs(y[i]-y_list[i])<__float_tol
100 testpass &= graph.GetLineColor() == line_color
101 testpass &= graph.GetLineStyle() == line_style
102 testpass &= graph.GetLineWidth() == line_width
103 testpass &= graph.GetFillColor() == fill_color