Skip to content

Commit 254868b

Browse files
committed
Switch to things missing, rather than percentage
1 parent ea6127a commit 254868b

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

scripts/hpc-ratchet

+23-29
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,20 @@ LOCAL_DECLS = 'local_decls'
2828
TOP_LEVEL_DECLS = 'top_level_decls'
2929

3030

31-
"""The coverage we actually want.
31+
"""The lack of coverage we are willing to tolerate.
3232
3333
In a just world, this would be a separate config file, or command-line arguments.
3434
35-
We round coverage ratios to three decimals before comparing,
36-
so there's no need to go more than that.
35+
Each item represents the number of "things" we are OK with not being covered.
3736
"""
38-
DESIRED_COVERAGE = {
39-
EXPRESSIONS: 0.571,
40-
BOOLEANS: 0.474,
41-
ALTERNATIVES: 0.454,
42-
LOCAL_DECLS: 0.814,
43-
TOP_LEVEL_DECLS: 0.325,
37+
COVERAGE_TOLERANCE = {
38+
ALTERNATIVES: 183,
39+
BOOLEANS: 10,
40+
EXPRESSIONS: 1619,
41+
LOCAL_DECLS: 16,
42+
TOP_LEVEL_DECLS: 725,
4443
}
4544

46-
DEFAULT_PRECISION = 3
47-
4845

4946
def get_report_summary():
5047
"""Run ``stack hpc report --all`` and return the output.
@@ -136,58 +133,55 @@ def parse_report_summary(summary):
136133
return report
137134

138135

139-
def compare_values((covered, total), target, precision=DEFAULT_PRECISION):
140-
"""Compare measured coverage values with desired ones.
136+
def compare_values((covered, total), tolerance):
137+
"""Compare measured coverage values with our tolerated lack of coverage.
141138
142-
Compares ``covered / total`` to ``target``, up to ``precision`` places.
139+
Return -1 if coverage has got worse, 0 if it is the same, 1 if it is better.
143140
"""
144-
actual = covered / total
145-
scale = 10 ** precision
146-
rounded_actual = int(round(actual * scale))
147-
rounded_target = int(round(target * scale))
148-
return cmp(rounded_actual, rounded_target)
141+
missing = total - covered
142+
return cmp(tolerance, missing)
149143

150144

151-
def compare_coverage(report, desired, precision=DEFAULT_PRECISION):
145+
def compare_coverage(report, desired):
152146
comparison = {}
153-
for key, target in desired.items():
147+
# TODO: Iterate over report and default to 0 for missing keys in desired.
148+
for key, tolerance in desired.items():
154149
actual = report.get(key, None)
155150
if actual:
156-
comparison[key] = compare_values(actual, target, precision=precision)
151+
comparison[key] = compare_values(actual, tolerance)
157152
else:
158153
comparison[key] = None
159154
return comparison
160155

161156

162157
def format_result(result):
163158
if result < 0:
164-
return 'DOWN'
159+
return 'WORSE'
165160
elif result == 0:
166161
return 'OK'
167162
else:
168-
return 'UP'
163+
return 'BETTER'
169164

170165

171166
def format_entry(key, result, desired, actual):
172167
covered, total = actual
173168
formatted_result = format_result(result)
174169
if result:
175-
return '%s: %s (%2.1f%% => %2.1f%%)' % (
176-
key, formatted_result, desired * 100,
177-
100 * covered / total,
170+
return '%s: %s (%d missing => %d missing)' % (
171+
key, formatted_result, desired, total - covered,
178172
)
179173
else:
180174
return '%s: %s' % (key, formatted_result)
181175

182176

183177
def main():
184178
report = parse_report_summary(get_report_summary())
185-
comparison = compare_coverage(report, DESIRED_COVERAGE)
179+
comparison = compare_coverage(report, COVERAGE_TOLERANCE)
186180
all_same = True
187181
for key, value in sorted(comparison.items()):
188182
if value != 0:
189183
all_same = False
190-
print format_entry(key, value, DESIRED_COVERAGE[key], report[key])
184+
print format_entry(key, value, COVERAGE_TOLERANCE[key], report[key])
191185
sys.exit(0 if all_same else 2)
192186

193187

0 commit comments

Comments
 (0)