forked from alchemyst/Skogestad-Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunall.py
80 lines (61 loc) · 2.18 KB
/
runall.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
#!/usr/bin/env python
from __future__ import print_function
from past.builtins import execfile
import traceback
import re
from collections import Counter
import sys
import time
import logging
logging.basicConfig(level=logging.DEBUG)
# disable show in figures
import matplotlib.pyplot as plt
plt.show = lambda: None
# disable print
def print(*args):
pass
statuscounter = Counter()
times = Counter()
itemparser = re.compile('(?P<kind>.*) (?P<chapter>.*)\.(?P<number>.*)')
kinds = ['Figure', 'Example', 'Exercise']
FAILED = 'Failed'
NOTIMPLEMENTED = 'Not implemented'
SUCCESS = 'Success'
faillist = []
if __name__ == "__main__":
with open('allitems.txt') as allitems:
for item in allitems:
kind, chapter_c, number_c = itemparser.match(item).groups()
number = int(number_c)
if chapter_c.isdigit():
chapter = int(chapter_c)
mask = 'reproductions/{}/{}_{:02d}_{:02d}.py'
else:
chapter = chapter_c
mask = 'reproductions/{}/{}_{}_{}.py'
filename = mask.format(kind, kind, chapter, number)
starttime = time.time()
try:
execfile(filename)
status = SUCCESS
except IOError:
status = NOTIMPLEMENTED
except Exception as err:
status = FAILED
message = traceback.format_exc()
times[(kind, chapter, number)] = time.time() - starttime
statuscounter[status] += 1
if status != NOTIMPLEMENTED:
logging.info(' '.join(str(thing) for thing in [kind, chapter, number, status]))
if status == FAILED:
faillist.append([kind, chapter, number])
logging.warning(message)
for items in statuscounter.items():
logging.info("{}: {}".format(*items))
logging.info("Failed items:")
for items in faillist:
logging.info(" {} {} {}".format(*items))
logging.info("Slowest tests")
for [(kind, chapter, number), elapsed] in times.most_common(5):
logging.info(" {} {} {} {}".format(kind, chapter, number, elapsed))
sys.exit(statuscounter[FAILED])