1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Run a series of tests.
18 """
19
20 import sys
21
22 from time import time
23
24 from numpy import zeros
25
26 from pypower.t.t_globals import TestGlobals
27
28
30 """Run a series of tests.
31
32 Runs a set of tests whose names
33 are given in the list C{test_names}. If the optional parameter
34 C{verbose} is true, it prints the details of the individual tests.
35
36 @author: Ray Zimmerman (PSERC Cornell)
37 @author: Richard Lincoln
38 """
39
40 if not verbose:
41 length = zeros(len(test_names), int)
42 for k in range(len(test_names)):
43 length[k] = len(test_names[k])
44 maxlen = max(length)
45
46
47 num_of_tests = 0
48 counter = 0
49 ok_cnt = 0
50 not_ok_cnt = 0
51 skip_cnt = 0
52
53 t0 = time()
54 for k in range(len(test_names)):
55 if verbose:
56 sys.stdout.write('\n---------- %s ----------\n' % test_names[k])
57 else:
58 pad = maxlen + 4 - len(test_names[k])
59 s = '%s' % test_names[k]
60 for _ in range(pad): s += '.'
61 sys.stdout.write(s)
62
63
64 tname = test_names[k]
65 __import__('pypower.t.'+tname)
66 mod = sys.modules['pypower.t.'+tname]
67 eval('mod.%s(not verbose)' % tname)
68
69 num_of_tests = num_of_tests + TestGlobals.t_num_of_tests
70 counter = counter + TestGlobals.t_counter
71 ok_cnt = ok_cnt + TestGlobals.t_ok_cnt
72 not_ok_cnt = not_ok_cnt + TestGlobals.t_not_ok_cnt
73 skip_cnt = skip_cnt + TestGlobals.t_skip_cnt
74
75 s = ''
76 status = 0
77 if verbose:
78 s += '\n\n---------- Summary ----------\n'
79
80 if (counter == num_of_tests) and (counter == ok_cnt + skip_cnt) and (not_ok_cnt == 0):
81 if skip_cnt:
82 s += 'All tests successful (%d passed, %d skipped of %d)' % \
83 (ok_cnt, skip_cnt, num_of_tests)
84 status = 0
85 else:
86 s += 'All tests successful (%d of %d)' % (ok_cnt, num_of_tests)
87 status = 0
88 else:
89 s += 'Ran %d of %d tests: %d passed, %d failed' % \
90 (counter, num_of_tests, ok_cnt, not_ok_cnt)
91 if skip_cnt:
92 s += ', %d skipped' % skip_cnt
93 status = 1
94
95 s += '\nElapsed time %.2f seconds.\n' % (time() - t0)
96 sys.stdout.write(s)
97
98 return status
99