Skip to content

Commit cd53609

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

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

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_read_helper_import_boundary.py` (shared mapping read-helper import boundary enforcement),
175+
- `tests/test_mapping_read_keys_helper_import_boundary.py` (shared mapping read-keys helper import boundary enforcement),
175176
- `tests/test_mapping_reader_usage.py` (shared mapping-read parser usage),
176177
- `tests/test_mapping_utils_import_boundary.py` (mapping utility import boundary enforcement),
177178
- `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_keys_helper_import_boundary.py",
4546
"tests/test_mapping_read_helper_import_boundary.py",
4647
"tests/test_mapping_reader_usage.py",
4748
"tests/test_mapping_utils_import_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+
from tests.test_tool_mapping_reader_usage import TOOLS_MODULE
7+
8+
pytestmark = pytest.mark.architecture
9+
10+
11+
EXPECTED_READ_KEYS_HELPER_EXTRA_IMPORTERS = ("tests/test_mapping_utils.py",)
12+
13+
14+
def _imports_read_string_mapping_keys(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_mapping_keys" for alias in node.names):
22+
return True
23+
return False
24+
25+
26+
def test_read_string_mapping_keys_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_mapping_keys(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_mapping_keys(module_text):
37+
discovered_modules.append(module_path.as_posix())
38+
39+
expected_modules = sorted(
40+
[TOOLS_MODULE.as_posix(), *EXPECTED_READ_KEYS_HELPER_EXTRA_IMPORTERS]
41+
)
42+
assert discovered_modules == expected_modules

0 commit comments

Comments
 (0)