Spaces:
Runtime error
Runtime error
Commit ·
e049ecd
1
Parent(s): 5ba7629
test(web): offline import-safety guard for proteus.web
Browse files
tests/web/test_import_safety.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Importing the web layer must not pull matplotlib or a provider SDK (offline
|
| 2 |
+
invariant — same discipline as tests/viz/test_import_safety.py)."""
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def test_importing_web_pulls_no_heavy_or_network_deps():
|
| 9 |
+
# Drop any pre-loaded matplotlib and proteus.web so we observe a fresh
|
| 10 |
+
# import graph even when earlier tests have cached these modules.
|
| 11 |
+
for mod in list(sys.modules):
|
| 12 |
+
if mod == "matplotlib" or mod.startswith("matplotlib."):
|
| 13 |
+
del sys.modules[mod]
|
| 14 |
+
for mod in list(sys.modules):
|
| 15 |
+
if mod == "proteus.web" or mod.startswith("proteus.web."):
|
| 16 |
+
del sys.modules[mod]
|
| 17 |
+
|
| 18 |
+
import proteus.web # noqa: F401
|
| 19 |
+
import proteus.web.server # noqa: F401
|
| 20 |
+
|
| 21 |
+
assert "matplotlib" not in sys.modules, (
|
| 22 |
+
"importing proteus.web pulled in matplotlib; keep the web layer offline"
|
| 23 |
+
)
|
| 24 |
+
# provider SDKs are never imported by the web layer
|
| 25 |
+
for sdk in ("openai", "anthropic", "google", "ollama"):
|
| 26 |
+
assert sdk not in sys.modules, (
|
| 27 |
+
f"importing proteus.web pulled in provider SDK {sdk!r}"
|
| 28 |
+
)
|