Spaces:
Runtime error
Runtime error
| """Importing the web layer must not pull matplotlib or a provider SDK (offline | |
| invariant — same discipline as tests/viz/test_import_safety.py).""" | |
| from __future__ import annotations | |
| import sys | |
| def test_importing_web_pulls_no_heavy_or_network_deps(): | |
| # Drop any pre-loaded matplotlib and proteus.web.local so we observe a fresh | |
| # import graph even when earlier tests have cached these modules. | |
| for mod in list(sys.modules): | |
| if mod == "matplotlib" or mod.startswith("matplotlib."): | |
| del sys.modules[mod] | |
| for mod in list(sys.modules): | |
| if mod == "proteus.web.local" or mod.startswith("proteus.web.local."): | |
| del sys.modules[mod] | |
| import proteus.web.local # noqa: F401 | |
| import proteus.web.local.server # noqa: F401 | |
| assert "matplotlib" not in sys.modules, ( | |
| "importing proteus.web.local pulled in matplotlib; keep the web layer offline" | |
| ) | |
| # provider SDKs are never imported by the web layer | |
| for sdk in ("openai", "anthropic", "google", "ollama"): | |
| assert sdk not in sys.modules, ( | |
| f"importing proteus.web.local pulled in provider SDK {sdk!r}" | |
| ) | |
| # spectate routes import providers LAZILY (inside the handler), so a plain | |
| # import of the web layer must still pull no provider SDK. | |
| import proteus.web.local.server # noqa: F401 (re-exercised after the clear above) | |
| for sdk in ("openai", "anthropic", "google", "ollama"): | |
| assert sdk not in sys.modules | |