Files
make-cad/test/test_drawing_lazy_pymupdf.py
NiJingzhe f55c7fe0e0 fix(inspect): make pymupdf an optional drawing extra
pymupdf (AGPL-3.0 / commercial dual license) was on the eager package
import path via inspect.drawing, so 'import simplecadapi' hard-failed
without it — including inside the render worker subprocess. The drawing
modules now bind a lazy proxy (real module under TYPE_CHECKING); the
first attribute access performs the import and a missing pymupdf raises
an ImportError naming the new 'drawing' extra.

Core install drops pymupdf; the dev extra keeps it for the test suite.
Verified: fresh venv without pymupdf and py-slvs passes import, build,
STEP export, render, solver-backend resolution; full suite 1941 passed /
5 skipped; ty diagnostics on the drawing package unchanged vs dev.
2026-10-09 18:31:38 +08:00

35 lines
1022 B
Python

"""pymupdf stays off the package import path; drawing functions name the extra."""
import builtins
import subprocess
import sys
import pytest
from simplecadapi.inspect.drawing._pymupdf import _LazyPymupdf
def test_package_import_does_not_pull_pymupdf() -> None:
code = (
"import sys, simplecadapi; "
"assert 'pymupdf' not in sys.modules, 'pymupdf imported eagerly'"
)
subprocess.run([sys.executable, "-c", code], check=True)
def test_missing_pymupdf_names_the_drawing_extra(monkeypatch: pytest.MonkeyPatch) -> None:
real_import = builtins.__import__
def poisoned(name, *args, **kwargs):
if name == "pymupdf":
raise ImportError(f"No module named '{name}'")
return real_import(name, *args, **kwargs)
monkeypatch.setattr(builtins, "__import__", poisoned)
with pytest.raises(ImportError, match=r"simplecadapi\[drawing\]"):
_LazyPymupdf().Rect
def test_present_pymupdf_passes_through() -> None:
assert callable(_LazyPymupdf().open)