Spaces:
Sleeping
Sleeping
| from __future__ import annotations | |
| import argparse | |
| import json | |
| import sys | |
| from pathlib import Path | |
| def main() -> int: | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument("stats_path", type=Path) | |
| parser.add_argument("--min-score", type=float, default=100.0) | |
| parser.add_argument("--max-survived", type=int, default=0) | |
| parser.add_argument("--max-timeout", type=int, default=0) | |
| parser.add_argument("--max-no-tests", type=int, default=0) | |
| args = parser.parse_args() | |
| stats = json.loads(args.stats_path.read_text()) | |
| killed = int(stats["killed"]) | |
| total = int(stats["total"]) | |
| survived = int(stats["survived"]) | |
| timeout = int(stats["timeout"]) | |
| no_tests = int(stats["no_tests"]) | |
| score = killed / total * 100 | |
| print( | |
| "mutmut score: " | |
| f"{score:.2f}% ({killed}/{total} killed, " | |
| f"{survived} survived, {timeout} timeout, {no_tests} no tests)" | |
| ) | |
| failures = [] | |
| if score < args.min_score: | |
| failures.append(f"score {score:.2f}% < {args.min_score:.2f}%") | |
| if survived > args.max_survived: | |
| failures.append(f"survived {survived} > {args.max_survived}") | |
| if timeout > args.max_timeout: | |
| failures.append(f"timeout {timeout} > {args.max_timeout}") | |
| if no_tests > args.max_no_tests: | |
| failures.append(f"no_tests {no_tests} > {args.max_no_tests}") | |
| if failures: | |
| print("mutmut gate failed: " + "; ".join(failures), file=sys.stderr) | |
| return 1 | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |