35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: MIT
|
|
"""Regression checks for measured benchmark and quality badges."""
|
|
|
|
import sys
|
|
import json
|
|
from pathlib import Path
|
|
from tempfile import TemporaryDirectory
|
|
import unittest
|
|
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
from metrics import bench_results, compact, quality_grade
|
|
|
|
|
|
class MetricTests(unittest.TestCase):
|
|
def test_quality_requires_both_static_checks(self):
|
|
with TemporaryDirectory() as directory:
|
|
path = Path(directory) / "quality.json"
|
|
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": True}))
|
|
self.assertEqual(quality_grade(path), "A")
|
|
path.write_text(json.dumps({"format": True, "clippy_warnings_denied": False}))
|
|
with self.assertRaises(ValueError):
|
|
quality_grade(path)
|
|
|
|
def test_benchmark_parser_and_short_si_badge(self):
|
|
with TemporaryDirectory() as directory:
|
|
path = Path(directory) / "bench.txt"
|
|
path.write_text("BENCH sha 42.125 ns/op\n")
|
|
self.assertEqual(bench_results(path), {"sha": 42.125})
|
|
self.assertEqual(compact(1234567), "1.23M")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|