forked from cleveragents/cleveragents-core
49 lines
1.7 KiB
Python
49 lines
1.7 KiB
Python
"""Benchmarks for coverage report configuration parsing."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
PYPROJECT_PATH = Path("pyproject.toml")
|
|
NOXFILE_PATH = Path("noxfile.py")
|
|
|
|
|
|
class CoverageConfigParseSuite:
|
|
"""Measure coverage configuration parsing performance."""
|
|
|
|
def setup(self) -> None:
|
|
"""Read configuration files once for reuse."""
|
|
self.pyproject_text = ""
|
|
self.noxfile_text = ""
|
|
if PYPROJECT_PATH.exists():
|
|
self.pyproject_text = PYPROJECT_PATH.read_text()
|
|
if NOXFILE_PATH.exists():
|
|
self.noxfile_text = NOXFILE_PATH.read_text()
|
|
|
|
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)
|
|
|
|
def time_parse_coverage_omit(self) -> None:
|
|
"""Benchmark extracting coverage omit patterns from pyproject.toml."""
|
|
if self.pyproject_text:
|
|
re.findall(r"omit\s*=\s*\[(.*?)\]", self.pyproject_text, re.DOTALL)
|
|
|
|
def time_parse_coverage_html_dir(self) -> None:
|
|
"""Benchmark extracting HTML directory from pyproject.toml."""
|
|
if self.pyproject_text:
|
|
re.search(r'directory\s*=\s*"([^"]+)"', self.pyproject_text)
|
|
|
|
def time_parse_coverage_xml_output(self) -> None:
|
|
"""Benchmark extracting XML output path from pyproject.toml."""
|
|
if self.pyproject_text:
|
|
re.search(r'output\s*=\s*"([^"]+)"', self.pyproject_text)
|