Skip to content

Commit 7a6789d

Browse files
Add mapping read-helper import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent c8a77a3 commit 7a6789d

3 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ This runs lint, format checks, compile checks, tests, and package build.
171171
- `tests/test_manager_parse_boundary.py` (manager response-parse boundary enforcement through shared helper modules),
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),
174+
- `tests/test_mapping_read_helper_import_boundary.py` (shared mapping read-helper import boundary enforcement),
174175
- `tests/test_mapping_reader_usage.py` (shared mapping-read parser usage),
175176
- `tests/test_mapping_utils_import_boundary.py` (mapping utility import boundary enforcement),
176177
- `tests/test_model_request_function_parse_boundary.py` (model-request function-level parse boundary enforcement between parsed wrappers and raw helpers),

‎tests/test_architecture_marker_usage.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"tests/test_manager_helper_import_boundary.py",
4343
"tests/test_manager_parse_boundary.py",
4444
"tests/test_manager_transport_boundary.py",
45+
"tests/test_mapping_read_helper_import_boundary.py",
4546
"tests/test_mapping_reader_usage.py",
4647
"tests/test_mapping_utils_import_boundary.py",
4748
"tests/test_mapping_keys_access_usage.py",
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
from tests.test_mapping_reader_usage import MAPPING_READER_TARGET_FILES
7+
8+
pytestmark = pytest.mark.architecture
9+
10+
11+
EXPECTED_READ_HELPER_EXTRA_IMPORTERS = ("tests/test_mapping_utils.py",)
12+
13+
14+
def _imports_read_string_key_mapping(module_text: str) -> bool:
15+
module_ast = ast.parse(module_text)
16+
for node in module_ast.body:
17+
if not isinstance(node, ast.ImportFrom):
18+
continue
19+
if node.module != "hyperbrowser.mapping_utils":
20+
continue
21+
if any(alias.name == "read_string_key_mapping" for alias in node.names):
22+
return True
23+
return False
24+
25+
26+
def test_read_string_key_mapping_imports_are_centralized():
27+
discovered_modules: list[str] = []
28+
29+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
30+
module_text = module_path.read_text(encoding="utf-8")
31+
if _imports_read_string_key_mapping(module_text):
32+
discovered_modules.append(module_path.as_posix())
33+
34+
for module_path in sorted(Path("tests").glob("test_*.py")):
35+
module_text = module_path.read_text(encoding="utf-8")
36+
if _imports_read_string_key_mapping(module_text):
37+
discovered_modules.append(module_path.as_posix())
38+
39+
expected_runtime_modules = sorted(
40+
path.as_posix() for path in MAPPING_READER_TARGET_FILES
41+
)
42+
expected_modules = sorted(
43+
[*expected_runtime_modules, *EXPECTED_READ_HELPER_EXTRA_IMPORTERS]
44+
)
45+
assert discovered_modules == expected_modules

0 commit comments

Comments
 (0)