1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 from qm.extension import Extension
21 from qm.test.result import Result
22 from qm.common import parse_time_iso
23
24
25
26
27
29 """A 'RunDatabase' stores 'TestRun's.
30
31 A 'RunDatabase' provides a mechanism for selecting 'TestRun's that
32 meet particular criteria."""
33
35 """Return all the 'TestRun's in the database.
36
37 returns -- A sequence consisting of all of the 'TestRun's in
38 the database."""
39
40 raise NotImplementedError
41
42
44 """Return the set of 'TestRun's satisfying 'predicate'
45
46 'predicate' -- A callable that can be passed one 'TestRun'
47 argument.
48
49 returns -- A sequence of 'TestRun's consisting only of those
50 'TestRun's in the database for which 'predicate' returns a
51 true value."""
52
53 return filter(self.GetAllRuns(), predicate)
54
55
57 """Return the set of annotations for 'key' from all test runs.
58
59 'key' -- A string used to look up the annotations.
60
61 returns -- A set of (distinct) annotations for 'key' from all
62 test runs."""
63
64
65 annotations = []
66 for r in self.GetAllRuns():
67 value = r.GetAnnotation(key)
68 if value not in annotations:
69 annotations.append(value)
70 return annotations
71
72
74 """Return a pair of min / max values found for the given time_key
75 across all test runs.
76
77 'time_key' -- Annotation key referring to a string convertible to
78 either iso-formatted time or floating point number.
79
80 returns -- minimum, maximum."""
81
82 minimum = None
83 maximum = None
84 for r in self.GetAllRuns():
85 time_string = r.GetAnnotation(time_key)
86 if not time_string:
87 continue
88 if is_iso_time:
89 time = parse_time_iso(time_string)
90 else:
91 time = float(time_string)
92 if not minimum or minimum > time:
93 minimum = time
94 if not maximum or maximum < time:
95
96 maximum = time + 0.1
97 return minimum, maximum
98
99
100 - def GetRunInTimeframe(self, key, value, time_key, minimum, maximum, is_iso_time = True):
101 """Return a test run id matching the key and timeframe."""
102
103 for i in range(len(self.GetAllRuns())):
104 r = self.GetAllRuns()[i]
105 if r.GetAnnotation(key) != value:
106 continue
107 time_string = r.GetAnnotation(time_key)
108 if not time_string:
109 continue
110 if is_iso_time:
111 time = parse_time_iso(time_string)
112 else:
113 time = float(time_string)
114 if time >= minimum and time < maximum:
115 return i
116
117 return None
118
119
121 """Return the 'TestRun's matching 'annotation_filter'.
122
123 'annotation_filter' -- A dictionary mapping annotation keys
124 (strings) to values (either strings or callables).
125
126 returns -- A sequence of 'TestRun's consisting only of those
127 'TestRun's in the database that match the
128 'annotation_filter'. A 'TestRun' matches the
129 'annotation_filter' if it matches each of the key-value pairs
130 in the filter. If the value in such a pair is a string, then
131 the annotation in the 'TestRun' must exactly match the value.
132 If the value is a callable, rather than a string, then when
133 passed the value from the 'TestRun', the predicate must return
134 a true value."""
135
136 def predicate(run):
137 for key, pattern in annotation_filter.iteritems():
138 value = run.GetAnnotation(key)
139 if callable(pattern):
140 if not pattern(value):
141 return False
142 elif value != pattern:
143 return False
144 return True
145
146 return self.GetRuns(predicate)
147
148
169