Skip to content

Commit a88b099

Browse files
Add mapping utils import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 6e5ba2a commit a88b099

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ This runs lint, format checks, compile checks, tests, and package build.
172172
- `tests/test_manager_transport_boundary.py` (manager transport boundary enforcement through shared request helpers),
173173
- `tests/test_mapping_keys_access_usage.py` (centralized key-iteration boundaries),
174174
- `tests/test_mapping_reader_usage.py` (shared mapping-read parser usage),
175+
- `tests/test_mapping_utils_import_boundary.py` (mapping utility import boundary enforcement),
175176
- `tests/test_model_request_function_parse_boundary.py` (model-request function-level parse boundary enforcement between parsed wrappers and raw helpers),
176177
- `tests/test_model_request_function_transport_boundary.py` (model-request function-level transport boundary enforcement between parsed wrappers and raw helpers),
177178
- `tests/test_model_request_internal_reuse.py` (request-helper internal reuse of shared model request helper primitives),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"tests/test_manager_parse_boundary.py",
4444
"tests/test_manager_transport_boundary.py",
4545
"tests/test_mapping_reader_usage.py",
46+
"tests/test_mapping_utils_import_boundary.py",
4647
"tests/test_mapping_keys_access_usage.py",
4748
"tests/test_model_request_function_parse_boundary.py",
4849
"tests/test_model_request_function_transport_boundary.py",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
EXPECTED_MAPPING_UTILS_IMPORTERS = (
10+
"hyperbrowser/client/managers/list_parsing_utils.py",
11+
"hyperbrowser/client/managers/response_utils.py",
12+
"hyperbrowser/tools/__init__.py",
13+
"hyperbrowser/transport/base.py",
14+
"tests/test_mapping_utils.py",
15+
)
16+
17+
18+
def _imports_mapping_utils(module_text: str) -> bool:
19+
module_ast = ast.parse(module_text)
20+
for node in module_ast.body:
21+
if not isinstance(node, ast.ImportFrom):
22+
continue
23+
if node.module != "hyperbrowser.mapping_utils":
24+
continue
25+
return True
26+
return False
27+
28+
29+
def test_mapping_utils_imports_are_centralized():
30+
discovered_modules: list[str] = []
31+
32+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
33+
module_text = module_path.read_text(encoding="utf-8")
34+
if _imports_mapping_utils(module_text):
35+
discovered_modules.append(module_path.as_posix())
36+
37+
for module_path in sorted(Path("tests").glob("test_*.py")):
38+
module_text = module_path.read_text(encoding="utf-8")
39+
if _imports_mapping_utils(module_text):
40+
discovered_modules.append(module_path.as_posix())
41+
42+
assert discovered_modules == list(EXPECTED_MAPPING_UTILS_IMPORTERS)

0 commit comments

Comments
 (0)