Skip to content

Commit f9f17ec

Browse files
Add unit tests for guardrail AST utilities
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 46a83c3 commit f9f17ec

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/test_guardrail_ast_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import ast
2+
3+
from tests.guardrail_ast_utils import (
4+
collect_attribute_call_lines,
5+
collect_list_keys_call_lines,
6+
collect_name_call_lines,
7+
)
8+
9+
10+
SAMPLE_MODULE = ast.parse(
11+
"""
12+
values = list(mapping.keys())
13+
result = helper()
14+
other = obj.method()
15+
"""
16+
)
17+
18+
19+
def test_collect_name_call_lines_returns_named_calls():
20+
assert collect_name_call_lines(SAMPLE_MODULE, "helper") == [3]
21+
22+
23+
def test_collect_attribute_call_lines_returns_attribute_calls():
24+
assert collect_attribute_call_lines(SAMPLE_MODULE, "method") == [4]
25+
26+
27+
def test_collect_list_keys_call_lines_returns_list_key_calls():
28+
assert collect_list_keys_call_lines(SAMPLE_MODULE) == [2]

0 commit comments

Comments
 (0)