diff --git a/screen_locker/tests/test_gate_select.py b/screen_locker/tests/test_gate_select.py index 798138d..05d95da 100644 --- a/screen_locker/tests/test_gate_select.py +++ b/screen_locker/tests/test_gate_select.py @@ -44,13 +44,10 @@ def test_helper_followed_by_import(tmp_path: Path) -> None: def test_untouched_change_selects_nothing(tmp_path: Path) -> None: _tree(tmp_path) - assert ( - gs.dart_affected_tests(tmp_path, [f"{APP}/lib/lonely.dart"]) - == [ - f"{APP}/test/lonely_test.dart", - f"{APP}/test/sub/x_test.dart", - ] - ) + assert gs.dart_affected_tests(tmp_path, [f"{APP}/lib/lonely.dart"]) == [ + f"{APP}/test/lonely_test.dart", + f"{APP}/test/sub/x_test.dart", + ] assert gs.dart_affected_tests(tmp_path, ["README.md"]) == [] diff --git a/scripts/gate_changed_coverage.py b/scripts/gate_changed_coverage.py index 7dc40f4..6ec340a 100644 --- a/scripts/gate_changed_coverage.py +++ b/scripts/gate_changed_coverage.py @@ -9,8 +9,10 @@ loads would otherwise score 100% by absence). from __future__ import annotations from pathlib import Path +import logging import sys +_LOG = logging.getLogger(__name__) APP_LIB = "stronglift_replacement/workout_app/lib/" @@ -39,15 +41,12 @@ def main(argv: list[str]) -> int: for path, lines in sorted( uncovered(Path(argv[1]).read_text(encoding="utf-8"), wanted).items() ): - if lines is None: - print(f"NOT COVERED (no selected test loads it): {path}", file=sys.stderr) + if lines is None or lines: + _LOG.error("changed file below 100%%: %s (uncovered: %s)", path, "absent from lcov" if lines is None else lines) bad += 1 - elif lines: - print(f"UNCOVERED LINES {path}: {lines}", file=sys.stderr) - bad += 1 - print(f"changed-file coverage: {len(wanted)} files, {bad} below 100%") return 1 if bad else 0 if __name__ == "__main__": + logging.basicConfig(level=logging.INFO, format="push-gate: %(message)s") raise SystemExit(main(sys.argv)) diff --git a/scripts/gate_select.py b/scripts/gate_select.py index bac3fc2..bf616a1 100644 --- a/scripts/gate_select.py +++ b/scripts/gate_select.py @@ -14,11 +14,13 @@ from __future__ import annotations from dataclasses import asdict, dataclass, field import json +import logging from pathlib import Path import re import subprocess import sys +_LOG = logging.getLogger(__name__) APP = "stronglift_replacement/workout_app" _DIRECTIVE = re.compile(r"^\s*(?:import|export|part)\s[^;]*;", re.MULTILINE) _QUOTED = re.compile(r"'([^']+)'|\"([^\"]+)\"") @@ -58,7 +60,7 @@ def _imports(root: Path, rel: str, pkg: str) -> set[str]: try: text = (root / rel).read_text(encoding="utf-8") except (OSError, UnicodeDecodeError) as exc: - print(f"gate_select: cannot read {rel}: {exc}", file=sys.stderr) + _LOG.warning("gate_select: cannot read %s: %s", rel, exc) return out for stmt in _DIRECTIVE.findall(text): for a, b in _QUOTED.findall(stmt): @@ -164,10 +166,11 @@ def _git(root: Path, *args: str) -> list[str]: def main(argv: list[str]) -> int: """Print the selection for BASE..HEAD as JSON.""" root = Path(_git(Path.cwd(), "rev-parse", "--show-toplevel")[0]) + logging.basicConfig(level=logging.INFO) base, head = argv[1], (argv[2] if len(argv) > 2 else "HEAD") changed = _git(root, "diff", "--name-only", f"{base}..{head}") sel = select(root, changed, _git(root, "ls-files", "*.py")) - print(json.dumps(asdict(sel), indent=1)) + sys.stdout.write(json.dumps(asdict(sel), indent=1) + "\n") return 0