8
# test_name ... OK (0.1 secs)
9
pattern = re.compile('^(.*) \.\.\. .*\((.*) secs\)$')
12
def gen_timings(output):
13
'''Filter out the test names and timing data into tuples.'''
14
for line in output.split('\n'):
16
test_name, seconds = re.match(pattern, line).groups()
17
except AttributeError:
19
seconds = float(seconds)
20
yield test_name, seconds
23
def sort_timings(timings):
24
'''Sort the timings based on the second value in the tuple, the time in
26
return sorted(timings, cmp=lambda x, y: cmp(x[1], y[1]))
29
def run_tests(args, test_command=['./run-tests']):
30
'''Call ./run-tests with any arguments passed to this program. Return
32
cmd = test_command + args
33
# Drop stderr. The text output from tests is not needed here.
34
with open('/dev/null', 'a') as devnull:
35
kwargs = {'stdout': subprocess.PIPE, 'stderr': devnull}
36
p = subprocess.Popen(cmd, **kwargs)
38
return p.communicate()[0]
39
except KeyboardInterrupt:
40
# Clean up the subprocess when we've interrupted this script.
47
def print_timings(timings):
48
for test_name, seconds in timings:
49
print '%s: %s' % (test_name, seconds)
52
def print_total_timing(timings):
53
total = sum([x[1] for x in timings])
54
output = 'Total test time: %.2f seconds' % total
56
print '-' * len(output)
60
if __name__ == '__main__':
61
output = run_tests(sys.argv[1:])
64
timings = gen_timings(output)
65
sorted_timings = sort_timings(timings)
66
print_timings(sorted_timings)
67
print_total_timing(sorted_timings)