Skip to content

Commit e80a897

Browse files
Enforce explicit display max-length keyword binding
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 6d4e361 commit e80a897

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tests/test_display_helper_usage.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pathlib import Path
2+
import ast
23

34
import pytest
45

@@ -54,3 +55,25 @@ def test_key_formatting_helper_usage_is_centralized():
5455
helper_usage_files.add(relative_path)
5556

5657
assert helper_usage_files == ALLOWED_KEY_FORMAT_CALL_FILES
58+
59+
60+
def test_key_formatting_helper_calls_use_explicit_max_length_keyword():
61+
missing_max_length_keyword_calls: list[str] = []
62+
63+
for path in _python_files():
64+
relative_path = path.relative_to(HYPERBROWSER_ROOT)
65+
if relative_path not in ALLOWED_KEY_FORMAT_CALL_FILES:
66+
continue
67+
module = read_module_ast(path)
68+
for node in ast.walk(module):
69+
if not isinstance(node, ast.Call):
70+
continue
71+
if not isinstance(node.func, ast.Name):
72+
continue
73+
if node.func.id != "format_string_key_for_error":
74+
continue
75+
if any(keyword.arg == "max_length" for keyword in node.keywords):
76+
continue
77+
missing_max_length_keyword_calls.append(f"{relative_path}:{node.lineno}")
78+
79+
assert missing_max_length_keyword_calls == []

0 commit comments

Comments
 (0)