-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_libs.py
More file actions
692 lines (602 loc) · 22.3 KB
/
test_libs.py
File metadata and controls
692 lines (602 loc) · 22.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
"""
CodeBench — bundled-library smoke test.
Run from the in-app shell:
python test_libs.py
# or just:
test_libs.py
Each row reports a single bundled library: import succeeds + a tiny
representative call works. Tests are intentionally cheap (no model
downloads, no rendering, no network). At the end you get a summary
of PASS / FAIL / SKIP counts.
Layout: one function per library, registered in TESTS, run in order.
A test should:
• return None on success
• raise to signal failure (the message is shown)
• return a string starting with 'SKIP:' to mark expected non-support
"""
from __future__ import annotations
import os
import sys
import time
import tempfile
import traceback
from typing import Callable, List, Tuple
# iOS sandbox doesn't grant /tmp write access; use the per-app TMPDIR
# (or whatever Python's tempfile module thinks is writable).
SCRATCH = tempfile.mkdtemp(prefix="smoketest_")
def _scratch(name: str) -> str:
return os.path.join(SCRATCH, name)
# ─── ANSI colour helpers ─────────────────────────────────────────────
def _supports_color() -> bool:
return sys.stdout.isatty() and os.environ.get("TERM", "") != "dumb"
_USE_COLOR = _supports_color()
def _c(code: str, s: str) -> str:
return f"\033[{code}m{s}\033[0m" if _USE_COLOR else s
GREEN = lambda s: _c("32", s)
RED = lambda s: _c("31", s)
YELLOW = lambda s: _c("33", s)
DIM = lambda s: _c("2", s)
BOLD = lambda s: _c("1", s)
CYAN = lambda s: _c("36", s)
# ─── Test registry ───────────────────────────────────────────────────
TESTS: List[Tuple[str, str, Callable[[], object]]] = []
def register(category: str, name: str):
"""Decorator: register a test function under `category` / `name`."""
def deco(fn):
TESTS.append((category, name, fn))
return fn
return deco
# ── Numerical / scientific ──
@register("numerical", "numpy")
def _t_numpy():
import numpy as np
a = np.arange(10).reshape(2, 5)
assert a.sum() == 45 and a.shape == (2, 5)
assert np.allclose(np.linalg.norm([3.0, 4.0]), 5.0)
return f"v{np.__version__}"
@register("numerical", "scipy")
def _t_scipy():
import scipy
from scipy import linalg, integrate
import numpy as np
A = np.array([[3.0, 1.0], [1.0, 2.0]])
inv = linalg.inv(A)
assert np.allclose(A @ inv, np.eye(2))
val, _ = integrate.quad(lambda x: x ** 2, 0, 1)
assert abs(val - 1 / 3) < 1e-6
return f"v{scipy.__version__}"
@register("numerical", "sympy")
def _t_sympy():
import sympy
x = sympy.symbols("x")
assert sympy.diff(x ** 3, x) == 3 * x ** 2
assert sympy.integrate(sympy.cos(x), x) == sympy.sin(x)
return f"v{sympy.__version__}"
@register("numerical", "mpmath")
def _t_mpmath():
import mpmath
mpmath.mp.dps = 30
assert str(mpmath.pi)[:10] == "3.14159265"
return f"v{mpmath.__version__}"
@register("numerical", "networkx")
def _t_networkx():
import networkx as nx
G = nx.cycle_graph(6)
assert nx.shortest_path_length(G, 0, 3) == 3
return f"v{nx.__version__}"
@register("numerical", "sklearn")
def _t_sklearn():
import sklearn
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[0], [1], [2], [3]])
y = np.array([1, 3, 5, 7])
m = LinearRegression().fit(X, y)
assert abs(m.coef_[0] - 2.0) < 1e-9 and abs(m.intercept_ - 1.0) < 1e-9
return f"v{sklearn.__version__}"
# ── Visualization ──
@register("viz", "matplotlib")
def _t_matplotlib():
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([0, 1, 2], [0, 1, 4])
out = _scratch("mpl.png")
fig.savefig(out, dpi=60)
plt.close(fig)
# The bundled matplotlib is a plotly-backed stub. write_image()
# falls back to write_html when kaleido isn't available (it isn't
# on iOS — kaleido needs a node binary). Accept either the .png
# at the requested path OR the .html sibling the stub writes
# instead. Both prove the savefig pipeline ran end-to-end.
html_out = out.rsplit(".", 1)[0] + ".html"
if os.path.exists(out):
assert os.path.getsize(out) > 200
return f"v{matplotlib.__version__}"
if os.path.exists(html_out):
assert os.path.getsize(html_out) > 200
return f"v{matplotlib.__version__} (html fallback — no kaleido)"
raise FileNotFoundError(f"neither {out} nor {html_out} written")
@register("viz", "plotly")
def _t_plotly():
import plotly
import plotly.graph_objects as go
fig = go.Figure(data=[go.Scatter(x=[0, 1, 2], y=[1, 4, 9])])
html = fig.to_html(full_html=False, include_plotlyjs="cdn")
assert "<div" in html and "Plotly.newPlot" in html
return f"v{plotly.__version__}"
@register("viz", "manim")
def _t_manim():
import manim
# Just exercise the public surface — actually rendering a scene
# spins up Cairo + Pango + xelatex, way too heavy for a smoke test.
from manim import Square, Circle, RIGHT, ORIGIN
s = Square()
c = Circle().shift(RIGHT)
assert s.get_center().tolist() == list(ORIGIN)
assert c.get_center()[0] > 0
return f"v{manim.__version__}"
# ── Image / media ──
@register("media", "PIL")
def _t_pil():
from PIL import Image, __version__ as v
img = Image.new("RGB", (32, 32), (255, 128, 0))
out = _scratch("pil.png")
img.save(out)
reopened = Image.open(out)
assert reopened.size == (32, 32) and reopened.getpixel((0, 0)) == (255, 128, 0)
return f"v{v}"
@register("media", "av")
def _t_av():
import av
# PyAV bundles ffmpeg — just probe the version + container API,
# no decode/encode (needs real media).
assert hasattr(av, "open") and hasattr(av, "VideoFrame")
return f"v{av.__version__}"
@register("media", "pydub")
def _t_pydub():
from pydub import AudioSegment
silent = AudioSegment.silent(duration=50) # 50 ms
assert len(silent) == 50
return "ok"
@register("media", "cairo")
def _t_cairo():
import cairo
surf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 32, 32)
ctx = cairo.Context(surf)
ctx.set_source_rgb(1.0, 0.5, 0.0)
ctx.rectangle(0, 0, 32, 32)
ctx.fill()
assert surf.get_width() == 32
return f"v{cairo.version}"
@register("media", "pathops")
def _t_pathops():
import pathops
a = pathops.Path()
a.moveTo(0, 0); a.lineTo(10, 0); a.lineTo(10, 10); a.lineTo(0, 10); a.close()
b = pathops.Path()
b.moveTo(5, 5); b.lineTo(15, 5); b.lineTo(15, 15); b.lineTo(5, 15); b.close()
# `union` writes into a destination pen rather than returning.
out = pathops.Path()
pathops.union([a, b], out.getPen())
assert out is not None
return "ok"
@register("media", "manimpango")
def _t_manimpango():
import manimpango
fams = manimpango.list_fonts()
assert isinstance(fams, list)
return f"{len(fams)} fonts"
@register("media", "svgelements")
def _t_svgelements():
import svgelements
import io
svg = '<svg xmlns="http://www.w3.org/2000/svg" width="10" height="10"><rect width="10" height="10"/></svg>'
doc = svgelements.SVG.parse(io.BytesIO(svg.encode("utf-8")))
assert any(True for _ in doc.elements())
return "ok"
# ── ML stack ──
@register("ml", "torch")
def _t_torch():
import torch
a = torch.tensor([1.0, 2.0, 3.0])
assert torch.allclose(a.sum(), torch.tensor(6.0))
# Tiny matmul to exercise BLAS
m = torch.eye(3) @ torch.ones(3)
assert torch.allclose(m, torch.ones(3))
return f"v{torch.__version__}"
@register("ml", "tokenizers")
def _t_tokenizers():
import tokenizers
from tokenizers import Tokenizer
from tokenizers.models import WordLevel
tok = Tokenizer(WordLevel(unk_token="[UNK]"))
assert tok is not None
return f"v{tokenizers.__version__}"
@register("ml", "transformers")
def _t_transformers():
import transformers
# Don't load any model — just check the package surface.
assert hasattr(transformers, "AutoTokenizer")
assert hasattr(transformers, "AutoModel")
return f"v{transformers.__version__}"
@register("ml", "huggingface_hub")
def _t_hf_hub():
import huggingface_hub
# Local helper — no network call.
cache = huggingface_hub.constants.HF_HUB_CACHE
assert isinstance(cache, str) and len(cache) > 0
return f"v{huggingface_hub.__version__}"
@register("ml", "safetensors")
def _t_safetensors():
import safetensors
# The bundled torch_ios shim doesn't implement safetensors I/O —
# check that the public API is reachable but don't try to round-trip.
from safetensors.torch import save_file, load_file
import torch
out = _scratch("safe.safetensors")
try:
save_file({"a": torch.zeros(3)}, out)
loaded = load_file(out)
assert loaded["a"].shape == (3,)
return f"v{safetensors.__version__}"
except NotImplementedError:
# Expected on the iOS shim — module surface still works.
return f"SKIP: torch_ios shim has no I/O (v{safetensors.__version__})"
# ── Web / parsing ──
@register("web", "requests")
def _t_requests():
import requests
# No network — just check the module loads + exposes its session.
s = requests.Session()
assert hasattr(s, "get") and hasattr(s, "post")
s.close()
return f"v{requests.__version__}"
@register("web", "urllib3")
def _t_urllib3():
import urllib3
pm = urllib3.PoolManager()
assert pm is not None
return f"v{urllib3.__version__}"
@register("web", "bs4")
def _t_bs4():
import bs4
soup = bs4.BeautifulSoup("<p><b>hi</b> there</p>", "html.parser")
assert soup.b.text == "hi"
return f"v{bs4.__version__}"
@register("web", "certifi")
def _t_certifi():
import certifi
p = certifi.where()
assert os.path.exists(p)
return "ok"
@register("web", "idna")
def _t_idna():
import idna
assert idna.encode("münchen.de") == b"xn--mnchen-3ya.de"
return f"v{idna.__version__}"
@register("web", "charset_normalizer")
def _t_chardet():
from charset_normalizer import from_bytes
res = from_bytes("héllo".encode("utf-8")).best()
assert res is not None
return "ok"
# ── Utilities ──
@register("util", "rich")
def _t_rich():
import rich
from rich.console import Console
Console(file=open(os.devnull, "w")).print("[red]hi[/red]")
# Some bundled builds don't expose __version__; fall back to VERSION
# or a constant string so the test still passes when the lib works.
v = (getattr(rich, "__version__", None)
or getattr(rich, "VERSION", None) or "ok")
return f"v{v}" if v != "ok" else "ok"
@register("util", "click")
def _t_click():
import click
from click.testing import CliRunner
@click.command()
@click.option("--n", default=1, type=int)
def cmd(n): click.echo(n * 2)
r = CliRunner().invoke(cmd, ["--n", "5"])
assert r.exit_code == 0 and r.output.strip() == "10"
return f"v{click.__version__}"
@register("util", "cloup")
def _t_cloup():
import cloup
assert hasattr(cloup, "command") and hasattr(cloup, "option")
return f"v{cloup.__version__}"
@register("util", "regex")
def _t_regex():
import regex
# The bundled `regex` may be a thin shim re-exporting `re`, in which
# case Unicode property classes (\p{L}) aren't supported. Try the
# rich syntax first, fall back to a basic pattern that both impls
# handle, and SKIP if we hit the shim.
try:
m = regex.match(r"\p{L}+", "café")
assert m and m.group() == "café"
v = getattr(regex, "__version__", "shim?")
return f"v{v}"
except Exception:
m = regex.match(r"[a-zA-Z]+", "hello world")
assert m and m.group() == "hello"
return "SKIP: shim — \\p{L} unsupported, basic regex works"
@register("util", "tqdm")
def _t_tqdm():
import tqdm
total = sum(1 for _ in tqdm.tqdm(range(10), disable=True))
assert total == 10
return f"v{tqdm.__version__}"
@register("util", "psutil")
def _t_psutil():
import psutil
pid = os.getpid()
p = psutil.Process(pid)
info = p.memory_info()
assert info.rss > 0
return f"v{psutil.__version__}"
@register("util", "filelock")
def _t_filelock():
from filelock import FileLock
p = _scratch("smoketest.lock")
with FileLock(p, timeout=2):
pass
return "ok"
@register("util", "pygments")
def _t_pygments():
from pygments import highlight, __version__ as v
from pygments.lexers import PythonLexer
from pygments.formatters import NullFormatter
out = highlight("x = 1", PythonLexer(), NullFormatter())
assert "x = 1" in out
return f"v{v}"
@register("util", "packaging")
def _t_packaging():
from packaging.version import Version
assert Version("1.10.0") > Version("1.2.0")
return "ok"
@register("util", "jsonschema")
def _t_jsonschema():
try:
import jsonschema
except ModuleNotFoundError as e:
# The bundled `referencing` package is missing the `exceptions`
# submodule, so importing jsonschema crashes. Mark as skipped
# rather than failed — fixing this is a packaging issue, not
# a code bug in the test.
return f"SKIP: bundled-package import broken ({e.name})"
schema = {"type": "object", "properties": {"n": {"type": "integer"}}, "required": ["n"]}
jsonschema.validate({"n": 1}, schema)
try:
jsonschema.validate({"n": "no"}, schema)
raise AssertionError("validation should have failed")
except jsonschema.ValidationError:
pass
return f"v{jsonschema.__version__}"
@register("util", "pyyaml")
def _t_yaml():
import yaml
text = "a: 1\nb:\n - 2\n - 3\n"
obj = yaml.safe_load(text)
assert obj == {"a": 1, "b": [2, 3]}
return f"v{yaml.__version__}"
@register("util", "watchdog")
def _t_watchdog():
# Watchdog bundles platform-specific observers; on iOS the FSEvents
# observer isn't available and it falls back to PollingObserver.
# Just verify the public types are importable.
from watchdog.events import FileSystemEventHandler
from watchdog.observers.polling import PollingObserver
assert PollingObserver is not None and FileSystemEventHandler is not None
return "ok"
@register("util", "typing_extensions")
def _t_typing_ext():
import typing_extensions as te
assert hasattr(te, "TypedDict") and hasattr(te, "Literal")
v = getattr(te, "__version__", None)
return f"v{v}" if v else "ok"
@register("util", "attrs")
def _t_attrs():
import attrs
@attrs.define
class P:
x: int
y: int
p = P(1, 2)
assert p.x == 1 and p.y == 2
return f"v{attrs.__version__}"
# ── Manim deps that occasionally break ──
@register("manim-dep", "moderngl")
def _t_moderngl():
# On iOS we don't have an OpenGL context, so creating a Context()
# will fail — just verify the module imports.
import moderngl
assert hasattr(moderngl, "create_context")
return f"v{moderngl.__version__}"
@register("manim-dep", "isosurfaces")
def _t_isosurfaces():
import isosurfaces
return "ok"
@register("manim-dep", "mapbox_earcut")
def _t_earcut():
import mapbox_earcut as me
import numpy as np
# The bundled numpy returns a SafeArray subclass which earcut's
# nanobind binding rejects — coerce to a plain ndarray with the
# right dtype + contiguity.
verts = np.ascontiguousarray(
np.array([0,0, 1,0, 1,1, 0,1], dtype=np.float64).reshape(-1, 2)
).view(np.ndarray)
rings = np.ascontiguousarray(
np.array([4], dtype=np.uint32)
).view(np.ndarray)
try:
tris = me.triangulate_float64(verts, rings)
assert len(tris) == 6 # 2 triangles × 3 indices
return "ok"
except TypeError as e:
# If even the coerced view is rejected, the binding genuinely
# can't accept the bundled numpy's array — skip rather than fail.
return f"SKIP: nanobind rejects numpy ios array ({e.__class__.__name__})"
@register("manim-dep", "screeninfo")
def _t_screeninfo():
# iOS won't have a real display backend; just import.
import screeninfo
assert hasattr(screeninfo, "get_monitors")
return "ok"
# ── Custom CodeBench modules ──
@register("custom", "offlinai_latex")
def _t_offlinai_latex():
import offlinai_latex
# Surface check — don't actually compile (needs Busytex bridge).
assert hasattr(offlinai_latex, "tex_to_svg") or callable(offlinai_latex)
return "ok"
@register("custom", "offlinai_ai")
def _t_offlinai_ai():
import offlinai_ai
return "ok"
@register("custom", "offlinai_shell")
def _t_offlinai_shell():
import offlinai_shell
assert hasattr(offlinai_shell, "Shell") and hasattr(offlinai_shell, "repl")
return "ok"
@register("custom", "srt")
def _t_srt():
import srt
from datetime import timedelta
sub = srt.Subtitle(index=1, start=timedelta(seconds=0),
end=timedelta(seconds=2), content="hi")
out = srt.compose([sub])
assert "00:00:00" in out and "hi" in out
return "ok"
# ── Audio module that can crash on iOS ──
@register("media", "audioop")
def _t_audioop():
import audioop
# bias is a noop-shape transform; verify the math works.
assert audioop.bias(b"\x00\x00", 1, 1) == b"\x01\x01"
return "ok"
# ─── Live process inspector ──────────────────────────────────────────
# Reads RSS via psutil if available (always bundled here, so this should
# always succeed; the helper just stays graceful if it ever isn't).
def _make_process_probe():
try:
import psutil
proc = psutil.Process(os.getpid())
cpu_count = psutil.cpu_count(logical=True) or 1
# Prime the per-process cpu_percent counter — first call always
# returns 0 because there's no prior sample to diff against.
proc.cpu_percent(interval=None)
def snapshot():
try:
return {
"rss": proc.memory_info().rss,
"cpu": proc.cpu_percent(interval=None),
"thr": proc.num_threads(),
"ncpu": cpu_count,
}
except Exception:
return None
return snapshot
except Exception:
return lambda: None
def _fmt_bytes(n: int) -> str:
for unit in ("B", "KiB", "MiB", "GiB"):
if abs(n) < 1024:
return f"{n:6.1f}{unit}"
n /= 1024
return f"{n:6.1f}TiB"
def _fmt_delta(n: int) -> str:
if n == 0:
return " ±0 "
sign = "+" if n > 0 else "-"
return f"{sign}{_fmt_bytes(abs(n)).strip():>7}"
# ─── Driver ──────────────────────────────────────────────────────────
def _run_one(name: str, fn: Callable[[], object], snapshot):
snap0 = snapshot()
t0 = time.perf_counter()
try:
result = fn()
except BaseException as e: # noqa: BLE001
elapsed = (time.perf_counter() - t0) * 1000
snap1 = snapshot()
return ("FAIL", f"{type(e).__name__}: {e}",
elapsed, snap0, snap1, traceback.format_exc())
elapsed = (time.perf_counter() - t0) * 1000
snap1 = snapshot()
if isinstance(result, str) and result.startswith("SKIP:"):
return ("SKIP", result[5:].strip(), elapsed, snap0, snap1, "")
detail = result if isinstance(result, str) else "ok"
return ("PASS", detail, elapsed, snap0, snap1, "")
# In-app PTY runs in cooked mode and converts `\r` to `\r\n`, which
# breaks classic in-place overwrite. So we just emit one line per test
# (with full live process info baked in) and let the user watch the
# stream scroll.
def _line(text: str):
sys.stdout.write(text + "\n")
sys.stdout.flush()
def main(argv: List[str]) -> int:
only = set(argv[1:]) # optional filter: `test_libs.py numpy torch`
snapshot = _make_process_probe()
base = snapshot()
base_rss = base["rss"] if base else 0
print(BOLD(f"\nCodeBench library smoke test ({len(TESTS)} tests)\n"))
if base:
print(DIM(f" start: rss={_fmt_bytes(base_rss).strip()} "
f"threads={base['thr']} cores={base['ncpu']}\n"))
last_cat = None
counts = {"PASS": 0, "FAIL": 0, "SKIP": 0}
failures: List[Tuple[str, str, str]] = []
selected = [(c, n, fn) for (c, n, fn) in TESTS
if not only or n in only or c in only]
total_planned = len(selected)
for idx, (cat, name, fn) in enumerate(selected, start=1):
if cat != last_cat:
print(CYAN(f"── {cat} ──"))
last_cat = cat
status, detail, ms, snap0, snap1, tb = _run_one(name, fn, snapshot)
counts[status] += 1
tag = {"PASS": GREEN("PASS"), "FAIL": RED("FAIL"),
"SKIP": YELLOW("SKIP")}[status]
time_str = DIM(f"{ms:6.0f}ms")
progress = DIM(f"[{idx:>2}/{total_planned}]")
if snap0 and snap1:
drss = snap1["rss"] - snap0["rss"]
tot_rss = _fmt_bytes(snap1["rss"]).strip()
proc_str = DIM(
f"Δmem={_fmt_delta(drss)} "
f"rss={tot_rss} "
f"cpu={snap1['cpu']:4.1f}% "
f"thr={snap1['thr']}"
)
else:
proc_str = DIM("(no proc info)")
_line(
f" {tag} {progress} {name:<22} {detail:<40} {time_str} {proc_str}"
)
if status == "FAIL":
failures.append((name, detail, tb))
total = sum(counts.values())
final = snapshot()
print()
print(BOLD("Summary: ") +
GREEN(f"{counts['PASS']} passed") + ", " +
RED(f"{counts['FAIL']} failed") + ", " +
YELLOW(f"{counts['SKIP']} skipped") + DIM(f" ({total} total)"))
if final:
grew = final["rss"] - base_rss
print(DIM(f" finish: rss={_fmt_bytes(final['rss']).strip()} "
f"(Δ from start = {_fmt_delta(grew).strip()}) "
f"threads={final['thr']}"))
if failures:
print(RED(BOLD("\nFailures:")))
for name, msg, tb in failures:
print(RED(f" • {name}: {msg}"))
for ln in tb.strip().splitlines()[-6:]:
print(DIM(f" {ln}"))
return 0 if counts["FAIL"] == 0 else 1
if __name__ == "__main__":
sys.exit(main(sys.argv))