Files
cleveragents-core/benchmarks/coverage_report_bench.py
brent.edwards bb3c4ffaef fix(qa): resolve merge conflicts with master and fix coverage threshold test
Merged master into feature/q0-min-coverage. Resolved conflicts in:
- benchmarks/coverage_report_bench.py: combined AST and regex benchmarks
- docs/development/testing.md: merged both versions into comprehensive guide
- robot/coverage_threshold.robot: merged test cases from both branches
- implementation_plan.md: kept both Brent and Luis notes

Fixed coverage_threshold_config test that failed because it expected
a literal --fail-under=97 but our noxfile uses the COVERAGE_THRESHOLD
constant via f-string. Updated step to resolve the constant via AST.
2026-02-13 22:25:16 +00:00

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)