Skip to content

Commit 8501ebb

Browse files
Add guard test for shared manager serialization path
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 4b159bb commit 8501ebb

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import ast
2+
from pathlib import Path
3+
4+
5+
MANAGERS_DIR = Path(__file__).resolve().parents[1] / "hyperbrowser" / "client" / "managers"
6+
7+
8+
def _manager_python_files() -> list[Path]:
9+
return sorted(
10+
path
11+
for path in MANAGERS_DIR.rglob("*.py")
12+
if path.name not in {"serialization_utils.py", "__init__.py"}
13+
)
14+
15+
16+
def test_manager_modules_use_shared_serialization_helper_only():
17+
offending_calls: list[str] = []
18+
19+
for path in _manager_python_files():
20+
source = path.read_text(encoding="utf-8")
21+
module = ast.parse(source, filename=str(path))
22+
for node in ast.walk(module):
23+
if not isinstance(node, ast.Call):
24+
continue
25+
if not isinstance(node.func, ast.Attribute):
26+
continue
27+
if node.func.attr != "model_dump":
28+
continue
29+
offending_calls.append(f"{path.relative_to(MANAGERS_DIR)}:{node.lineno}")
30+
31+
assert offending_calls == []

0 commit comments

Comments
 (0)