Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Simple percentage report of end of tests output.
#!./bin/python
"""
Simple percentage report of end of tests output. Copy the line from there and pass to script:
usage: $./calc_test_percentages.py 9372 tests, 180 failures, 324 errors and 266 skipped in 22 minutes 25.188 seconds
output:
green : 91.784%
failures: 1.921%
errors : 3.457%
skipped : 2.838%
"""
import re
import sys
exp_ints = re.compile(r"\d+")
exp_words = re.compile(r"[a-z]+")
s = " ".join(sys.argv[1:])
counts = [float(x) for x in exp_ints.findall(s)]
words = [x for x in exp_words.findall(s) if x not in ["in", "and"]]
nums = dict(zip(words, counts))
nums["seconds"] = nums["minutes"] * 60 + nums["seconds"]
del nums["minutes"]
failures = 100 * nums["failures"] / nums["tests"]
errors = 100 * nums["errors"] / nums["tests"]
skipped = 100 * nums["skipped"] / nums["tests"]
green = 100 - (
100 * (nums["failures"] + nums["errors"] + nums["skipped"]) / nums["tests"]
)
report = f"""\
green : {green:2.3f}%
failures: {failures:2.3f}%
errors : {errors:2.3f}%
skipped : {skipped:2.3f}%
"""
print(report)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.