review batch script

This commit is contained in:
ed
2026-06-15 20:02:36 -04:00
parent 25d047fa75
commit 4419922bce
+16 -31
View File
@@ -110,35 +110,26 @@ def _format_pytest_line(line: str) -> str | None:
return None return None
if stripped.startswith(("tests/", "tests\\")) and "::" in stripped and len(stripped.split()) == 1: if stripped.startswith(("tests/", "tests\\")) and "::" in stripped and len(stripped.split()) == 1:
return None return None
if " PASSED " in stripped and "[gw" in stripped: if " PASSED " in stripped and "[gw" in stripped: return _c(stripped, _C.GREEN)
return _c(stripped, _C.GREEN) if " FAILED " in stripped and "[gw" in stripped: return _c(stripped, _C.BOLD_RED)
if " FAILED " in stripped and "[gw" in stripped: if " ERROR " in stripped and "[gw" in stripped: return _c(stripped, _C.BOLD_RED)
return _c(stripped, _C.BOLD_RED)
if " ERROR " in stripped and "[gw" in stripped:
return _c(stripped, _C.BOLD_RED)
if stripped.startswith(("tests/", "tests\\")) and "::" in stripped: if stripped.startswith(("tests/", "tests\\")) and "::" in stripped:
if " PASSED" in stripped: if " PASSED" in stripped: return _c(stripped, _C.GREEN)
return _c(stripped, _C.GREEN) if " FAILED" in stripped: return _c(stripped, _C.BOLD_RED)
if " FAILED" in stripped: if " ERROR" in stripped: return _c(stripped, _C.BOLD_RED)
return _c(stripped, _C.BOLD_RED)
if " ERROR" in stripped:
return _c(stripped, _C.BOLD_RED)
if stripped.startswith(("PASSED", "FAILED", "ERROR")) and "::" in stripped: if stripped.startswith(("PASSED", "FAILED", "ERROR")) and "::" in stripped:
status = stripped.split()[0] status = stripped.split()[0]
rest = stripped[len(status):] res = stripped[len(status):]
if status == "PASSED": if status == "PASSED": return _c(f"{status}{rest}", _C.GREEN)
return _c(f"{status}{rest}", _C.GREEN)
return _c(f"{status}{rest}", _C.BOLD_RED) return _c(f"{status}{rest}", _C.BOLD_RED)
if stripped.startswith(("passed", "failed", "error")) and " in " in stripped and stripped.endswith("s"): if stripped.startswith(("passed", "failed", "error")) and " in " in stripped and stripped.endswith("s"):
return _c(stripped, _C.BOLD) return _c(stripped, _C.BOLD)
return stripped return stripped
def _run_batch(b: Batch, durations: dict[str, float]) -> tuple[int, float, dict[str, float]]: def _run_batch(b: Batch, durations: dict[str, float]) -> tuple[int, float, dict[str, float]]:
if b.skip_reason: if b.skip_reason: return 0, 0.0, {}
return 0, 0.0, {}
args = list(b.pytest_args) args = list(b.pytest_args)
if not _HAS_XDIST: if not _HAS_XDIST: args = [a for a in args if a not in {"-n", "auto"}]
args = [a for a in args if a not in {"-n", "auto"}]
cmd = ["uv", "run", "pytest", "-v", "--durations=3"] + args + [str(f) for f in b.files] cmd = ["uv", "run", "pytest", "-v", "--durations=3"] + args + [str(f) for f in b.files]
print(_c(f"\n>>> Running {b.label} ({len(b.files)} files)", _C.BOLD_CYAN)) print(_c(f"\n>>> Running {b.label} ({len(b.files)} files)", _C.BOLD_CYAN))
t0 = time.monotonic() t0 = time.monotonic()
@@ -148,8 +139,7 @@ def _run_batch(b: Batch, durations: dict[str, float]) -> tuple[int, float, dict[
for line in proc.stdout: for line in proc.stdout:
captured.append(line) captured.append(line)
formatted = _format_pytest_line(line) formatted = _format_pytest_line(line)
if formatted is None: if formatted is None: continue
continue
print(formatted) print(formatted)
proc.wait() proc.wait()
elapsed = time.monotonic() - t0 elapsed = time.monotonic() - t0
@@ -157,10 +147,8 @@ def _run_batch(b: Batch, durations: dict[str, float]) -> tuple[int, float, dict[
captured_text = "".join(captured) captured_text = "".join(captured)
saw_failure = "FAILED " in captured_text or " stopping after " in captured_text saw_failure = "FAILED " in captured_text or " stopping after " in captured_text
effective_code = proc.returncode if proc.returncode != 0 else (1 if saw_failure else 0) effective_code = proc.returncode if proc.returncode != 0 else (1 if saw_failure else 0)
if effective_code == 0: if effective_code == 0: print(_c(f"<<< {b.label} PASS in {elapsed:.1f}s", _C.BOLD_GREEN))
print(_c(f"<<< {b.label} PASS in {elapsed:.1f}s", _C.BOLD_GREEN)) else: print(_c(f"<<< {b.label} FAIL (exit {effective_code}) in {elapsed:.1f}s", _C.BOLD_RED))
else:
print(_c(f"<<< {b.label} FAIL (exit {effective_code}) in {elapsed:.1f}s", _C.BOLD_RED))
return effective_code, elapsed, new_durs return effective_code, elapsed, new_durs
def _print_summary(results: list[tuple[Batch, int, float]]) -> int: def _print_summary(results: list[tuple[Batch, int, float]]) -> int:
@@ -198,12 +186,9 @@ def _print_summary(results: list[tuple[Batch, int, float]]) -> int:
print(_c(header, _C.BOLD)) print(_c(header, _C.BOLD))
print(_c(sep, _C.DIM)) print(_c(sep, _C.DIM))
for tier, label, status_text, n, elapsed, _code in rows: for tier, label, status_text, n, elapsed, _code in rows:
if status_text == "PASS": if status_text == "PASS": status = _c(status_text, _C.BOLD_GREEN)
status = _c(status_text, _C.BOLD_GREEN) elif status_text == "FAIL": status = _c(status_text, _C.BOLD_RED)
elif status_text == "FAIL": else: status = _c(status_text, _C.BOLD_YELLOW)
status = _c(status_text, _C.BOLD_RED)
else:
status = _c(status_text, _C.BOLD_YELLOW)
tier_colored = _c(f" {tier:<{tier_w}s}", _C.CYAN) tier_colored = _c(f" {tier:<{tier_w}s}", _C.CYAN)
print(f"{tier_colored}{label:<{label_w}s}{status}{n:>{files_w}d}{elapsed:>{time_w - 1}.1f}s") print(f"{tier_colored}{label:<{label_w}s}{status}{n:>{files_w}d}{elapsed:>{time_w - 1}.1f}s")
print(_c(sep, _C.DIM)) print(_c(sep, _C.DIM))