|
16 | 16 | from vesskel.cli import _discover_input_paths |
17 | 17 | from vesskel.config import CONFIG_SCHEMA_VERSION, PipelineConfig |
18 | 18 |
|
| 19 | +HEAVY_MODULES = frozenset( |
| 20 | + {"numpy", "PIL", "PIL.Image", "vesskel.pipeline", "vesskel._batch"} |
| 21 | +) |
| 22 | + |
| 23 | + |
| 24 | +class TestCompletionSpeed: |
| 25 | + """Shell completions must exit before importing heavy modules (numpy/PIL).""" |
| 26 | + |
| 27 | + def test_completions_skip_heavy_imports(self): |
| 28 | + import subprocess |
| 29 | + import sys |
| 30 | + |
| 31 | + heavy_modules = sorted(HEAVY_MODULES) |
| 32 | + probe = f""" |
| 33 | +import os, sys |
| 34 | +
|
| 35 | +def _fake_exit(code=0): |
| 36 | + raise SystemExit(code) |
| 37 | +os._exit = _fake_exit |
| 38 | +
|
| 39 | +os.environ["_ARGCOMPLETE"] = "1" |
| 40 | +sys.argv = ["vesskel", "complete", "zsh"] |
| 41 | +
|
| 42 | +try: |
| 43 | + import vesskel.cli |
| 44 | +except SystemExit: |
| 45 | + pass |
| 46 | +
|
| 47 | +heavy = [m for m in {heavy_modules!r} if m in sys.modules] |
| 48 | +if heavy: |
| 49 | + sys.stdout.write("HEAVY:" + ",".join(heavy)) |
| 50 | +""" |
| 51 | + result = subprocess.run( |
| 52 | + [sys.executable, "-c", probe], |
| 53 | + capture_output=True, |
| 54 | + text=True, |
| 55 | + timeout=15, |
| 56 | + ) |
| 57 | + assert result.returncode == 0, f"Subprocess failed (stderr): {result.stderr}" |
| 58 | + assert ( |
| 59 | + "HEAVY:" not in result.stdout |
| 60 | + ), f"Heavy modules loaded during completions: {result.stdout}" |
| 61 | + assert ( |
| 62 | + "HEAVY:" not in result.stderr |
| 63 | + ), f"Heavy modules leaked to stderr: {result.stderr}" |
| 64 | + |
19 | 65 |
|
20 | 66 | class TestDiscoverInputPaths: |
21 | 67 | def test_single_png_file(self, tmp_path): |
|
0 commit comments