Skip to content

Commit ab1f84a

Browse files
Add display normalize import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 5968c0a commit ab1f84a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ This runs lint, format checks, compile checks, tests, and package build.
122122
- `tests/test_display_blank_key_literal_boundary.py` (blank-key display literal centralization in `hyperbrowser/display_utils.py`),
123123
- `tests/test_display_helper_usage.py` (display/key-format helper usage),
124124
- `tests/test_display_key_format_import_boundary.py` (display key-format helper import boundary enforcement),
125+
- `tests/test_display_normalize_import_boundary.py` (display normalization helper import boundary enforcement),
125126
- `tests/test_docs_python3_commands.py` (`README`/`CONTRIBUTING`/examples python3 command consistency enforcement),
126127
- `tests/test_example_run_instructions.py` (example run-instruction consistency enforcement),
127128
- `tests/test_example_sync_async_parity.py` (sync/async example parity enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"tests/test_display_blank_key_literal_boundary.py",
5353
"tests/test_display_helper_usage.py",
5454
"tests/test_display_key_format_import_boundary.py",
55+
"tests/test_display_normalize_import_boundary.py",
5556
"tests/test_file_open_default_prefix_literal_boundary.py",
5657
"tests/test_file_message_default_constant_import_boundary.py",
5758
"tests/test_file_message_default_constant_usage.py",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
EXPECTED_NORMALIZE_DISPLAY_IMPORTERS = (
10+
"hyperbrowser/client/managers/response_utils.py",
11+
"hyperbrowser/transport/base.py",
12+
"tests/test_display_utils.py",
13+
)
14+
15+
16+
def _imports_normalize_display_text(module_text: str) -> bool:
17+
module_ast = ast.parse(module_text)
18+
for node in module_ast.body:
19+
if not isinstance(node, ast.ImportFrom):
20+
continue
21+
if any(alias.name == "normalize_display_text" for alias in node.names):
22+
return True
23+
return False
24+
25+
26+
def test_normalize_display_text_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_normalize_display_text(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_normalize_display_text(module_text):
37+
discovered_modules.append(module_path.as_posix())
38+
39+
assert discovered_modules == list(EXPECTED_NORMALIZE_DISPLAY_IMPORTERS)

0 commit comments

Comments
 (0)