@@ -137,7 +137,7 @@ def sync_function():
137137 assert sync_func .is_async is False
138138
139139 def test_discover_nested_functions (self , python_support ):
140- """Test discovering nested functions."""
140+ """Test that nested functions are excluded — only top-level and class-level functions are discovered ."""
141141 with tempfile .NamedTemporaryFile (suffix = ".py" , mode = "w" , delete = False ) as f :
142142 f .write ("""
143143def outer():
@@ -149,16 +149,9 @@ def inner():
149149
150150 functions = python_support .discover_functions (Path (f .name ))
151151
152- # Both outer and inner should be discovered
153- assert len (functions ) == 2
154- names = {func .function_name for func in functions }
155- assert names == {"outer" , "inner" }
156-
157- # Inner should have outer as parent
158- inner = next (f for f in functions if f .function_name == "inner" )
159- assert len (inner .parents ) == 1
160- assert inner .parents [0 ].name == "outer"
161- assert inner .parents [0 ].type == "FunctionDef"
152+ # Only outer should be discovered; inner is nested and skipped
153+ assert len (functions ) == 1
154+ assert functions [0 ].function_name == "outer"
162155
163156 def test_discover_static_method (self , python_support ):
164157 """Test discovering static methods."""
@@ -237,19 +230,21 @@ def func2():
237230 assert func2 .starting_line == 4
238231 assert func2 .ending_line == 7
239232
240- def test_discover_invalid_file_returns_empty (self , python_support ):
241- """Test that invalid Python file returns empty list."""
233+ def test_discover_invalid_file_raises (self , python_support ):
234+ """Test that invalid Python file raises a parse error."""
235+ from libcst ._exceptions import ParserSyntaxError
236+
242237 with tempfile .NamedTemporaryFile (suffix = ".py" , mode = "w" , delete = False ) as f :
243238 f .write ("this is not valid python {{{{" )
244239 f .flush ()
245240
246- functions = python_support . discover_functions ( Path ( f . name ))
247- assert functions == []
241+ with pytest . raises ( ParserSyntaxError ):
242+ python_support . discover_functions ( Path ( f . name ))
248243
249- def test_discover_nonexistent_file_returns_empty (self , python_support ):
250- """Test that nonexistent file returns empty list ."""
251- functions = python_support . discover_functions ( Path ( "/nonexistent/file.py" ))
252- assert functions == []
244+ def test_discover_nonexistent_file_raises (self , python_support ):
245+ """Test that nonexistent file raises FileNotFoundError ."""
246+ with pytest . raises ( FileNotFoundError ):
247+ python_support . discover_functions ( Path ( "/nonexistent/file.py" ))
253248
254249
255250class TestReplaceFunction :
@@ -584,12 +579,7 @@ def process(value):
584579 return helper_function(value) + 1
585580""" )
586581
587- func = FunctionToOptimize (
588- function_name = "helper_function" ,
589- file_path = source_file ,
590- starting_line = 1 ,
591- ending_line = 2 ,
592- )
582+ func = FunctionToOptimize (function_name = "helper_function" , file_path = source_file , starting_line = 1 , ending_line = 2 )
593583
594584 refs = python_support .find_references (func , project_root = tmp_path )
595585
@@ -646,12 +636,7 @@ def test_find_references_no_references(python_support, tmp_path):
646636 return 42
647637""" )
648638
649- func = FunctionToOptimize (
650- function_name = "isolated_function" ,
651- file_path = source_file ,
652- starting_line = 1 ,
653- ending_line = 2 ,
654- )
639+ func = FunctionToOptimize (function_name = "isolated_function" , file_path = source_file , starting_line = 1 , ending_line = 2 )
655640
656641 refs = python_support .find_references (func , project_root = tmp_path )
657642
@@ -668,10 +653,7 @@ def test_find_references_nonexistent_function(python_support, tmp_path):
668653""" )
669654
670655 func = FunctionToOptimize (
671- function_name = "nonexistent_function" ,
672- file_path = source_file ,
673- starting_line = 1 ,
674- ending_line = 2 ,
656+ function_name = "nonexistent_function" , file_path = source_file , starting_line = 1 , ending_line = 2
675657 )
676658
677659 refs = python_support .find_references (func , project_root = tmp_path )
0 commit comments