36c571db83
CI / lint (pull_request) Successful in 15s
CI / typecheck (pull_request) Successful in 30s
CI / security (pull_request) Successful in 22s
CI / quality (pull_request) Successful in 16s
CI / integration_tests (pull_request) Successful in 5m12s
CI / build (pull_request) Successful in 16s
CI / lint (push) Successful in 13s
CI / typecheck (push) Successful in 29s
CI / security (push) Successful in 23s
CI / quality (push) Successful in 16s
CI / unit_tests (pull_request) Successful in 13m42s
CI / integration_tests (push) Successful in 4m53s
CI / build (push) Successful in 16s
CI / unit_tests (push) Successful in 15m9s
CI / coverage (pull_request) Successful in 7m58s
CI / coverage (push) Successful in 8m14s
CI / docker (pull_request) Successful in 9s
CI / docker (push) Successful in 8s
70 lines
2.4 KiB
Python
70 lines
2.4 KiB
Python
"""Benchmarks for coverage configuration parsing and threshold validation."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import ast
|
|
import re
|
|
from pathlib import Path
|
|
|
|
NOXFILE_PATH = Path("noxfile.py")
|
|
PYPROJECT_PATH = Path("pyproject.toml")
|
|
|
|
|
|
class TimeCoverageConfigParsing:
|
|
"""Measure coverage configuration parsing performance."""
|
|
|
|
def setup(self) -> None:
|
|
"""Read source files once for reuse."""
|
|
if NOXFILE_PATH.exists():
|
|
self.noxfile_text = NOXFILE_PATH.read_text()
|
|
else:
|
|
self.noxfile_text = ""
|
|
if PYPROJECT_PATH.exists():
|
|
self.pyproject_text = PYPROJECT_PATH.read_text()
|
|
else:
|
|
self.pyproject_text = ""
|
|
|
|
def time_parse_noxfile_ast(self) -> None:
|
|
"""Benchmark AST parsing of noxfile.py."""
|
|
if self.noxfile_text:
|
|
ast.parse(self.noxfile_text)
|
|
|
|
def time_extract_threshold_constant(self) -> None:
|
|
"""Benchmark extracting COVERAGE_THRESHOLD from noxfile AST."""
|
|
if self.noxfile_text:
|
|
tree = ast.parse(self.noxfile_text)
|
|
for node in ast.walk(tree):
|
|
if isinstance(node, ast.Assign):
|
|
for target in node.targets:
|
|
if (
|
|
isinstance(target, ast.Name)
|
|
and target.id == "COVERAGE_THRESHOLD"
|
|
and isinstance(node.value, ast.Constant)
|
|
):
|
|
_ = node.value.value
|
|
|
|
def time_parse_pyproject_toml(self) -> None:
|
|
"""Benchmark TOML parsing of pyproject.toml."""
|
|
if self.pyproject_text:
|
|
import tomllib
|
|
|
|
tomllib.loads(self.pyproject_text)
|
|
|
|
def time_extract_coverage_config(self) -> None:
|
|
"""Benchmark extracting coverage config from pyproject.toml."""
|
|
if self.pyproject_text:
|
|
import tomllib
|
|
|
|
data = tomllib.loads(self.pyproject_text)
|
|
_ = data.get("tool", {}).get("coverage", {}).get("run", {})
|
|
|
|
def time_parse_coverage_source(self) -> None:
|
|
"""Benchmark extracting coverage source list from pyproject.toml."""
|
|
if self.pyproject_text:
|
|
re.findall(r"source\s*=\s*\[([^\]]+)\]", self.pyproject_text)
|
|
|
|
def time_parse_fail_under(self) -> None:
|
|
"""Benchmark extracting fail-under threshold from noxfile."""
|
|
if self.noxfile_text:
|
|
re.findall(r"--fail-under=(\d+)", self.noxfile_text)
|