Skip to content

Commit 6c636bf

Browse files
Cover AST function-source helper top-level extraction semantics
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent fcebde9 commit 6c636bf

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

tests/test_ast_function_source_utils.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,23 @@ def test_collect_function_sources_reads_sync_and_async_functions():
2121
assert "post_model_response_data_async(" in function_sources[
2222
"post_model_request_async"
2323
]
24+
25+
26+
def test_collect_function_sources_returns_top_level_functions_only(tmp_path):
27+
module_path = tmp_path / "sample_module.py"
28+
module_path.write_text(
29+
"def top_level():\n"
30+
" return 'ok'\n\n"
31+
"class Example:\n"
32+
" def method(self):\n"
33+
" return 'method'\n\n"
34+
"def wrapper():\n"
35+
" def nested():\n"
36+
" return 'nested'\n"
37+
" return nested()\n",
38+
encoding="utf-8",
39+
)
40+
41+
function_sources = collect_function_sources(str(module_path))
42+
43+
assert sorted(function_sources.keys()) == ["top_level", "wrapper"]

0 commit comments

Comments
 (0)