@@ -117,7 +117,9 @@ def helper_function_2(x):
117117 original_helper_code = {main_file : main_file .read_text ()}
118118
119119 # Apply optimization and test reversion
120- optimizer .replace_function_and_helpers_with_optimized_code (code_context , optimized_code_with_modified_helper , original_helper_code )
120+ optimizer .replace_function_and_helpers_with_optimized_code (
121+ code_context , optimized_code_with_modified_helper , original_helper_code
122+ )
121123
122124 # Check final file content
123125 final_content = main_file .read_text ()
@@ -377,7 +379,7 @@ def helper_function_1(x):
377379def helper_function_2(x):
378380 \" \" \" Second helper function.\" \" \"
379381 return x * 3
380- """
382+ """ ,
381383 }
382384
383385 # Apply optimization and test reversion
@@ -426,7 +428,7 @@ def helper_function_1(x):
426428def helper_function_2(x):
427429 \" \" \" Second helper function.\" \" \"
428430 return x * 3
429- """
431+ """ ,
430432 }
431433
432434 # Apply optimization and test reversion
@@ -554,7 +556,9 @@ def helper_method_2(self, x):
554556 original_helper_code = {main_file : main_file .read_text ()}
555557
556558 # Apply optimization and test reversion
557- optimizer .replace_function_and_helpers_with_optimized_code (code_context , optimized_code_with_modified_helper , original_helper_code )
559+ optimizer .replace_function_and_helpers_with_optimized_code (
560+ code_context , optimized_code_with_modified_helper , original_helper_code
561+ )
558562
559563 # Check final file content
560564 final_content = main_file .read_text ()
@@ -693,7 +697,9 @@ def process_data(self, n):
693697 original_helper_code = {main_file : main_file .read_text ()}
694698
695699 # Apply optimization and test reversion
696- optimizer .replace_function_and_helpers_with_optimized_code (code_context , optimized_code_with_modified_helper , original_helper_code )
700+ optimizer .replace_function_and_helpers_with_optimized_code (
701+ code_context , optimized_code_with_modified_helper , original_helper_code
702+ )
697703
698704 # Check final file content
699705 final_content = main_file .read_text ()
@@ -729,7 +735,9 @@ def process_data(self, n):
729735 original_helper_code = {main_file : main_file .read_text ()}
730736
731737 # Apply optimization and test reversion
732- optimizer .replace_function_and_helpers_with_optimized_code (code_context , optimized_code_with_modified_helper , original_helper_code )
738+ optimizer .replace_function_and_helpers_with_optimized_code (
739+ code_context , optimized_code_with_modified_helper , original_helper_code
740+ )
733741
734742 # Check final file content
735743 final_content = main_file .read_text ()
@@ -994,8 +1002,9 @@ def entrypoint_function(n):
9941002
9951003 # The exact unused functions may vary based on what helpers are discovered by Jedi
9961004 # At minimum, we expect multiply to be detected as unused since it's not imported
997- print (f"Detected unused helpers: { unused_names } " )
998- print (f"All helpers in context: { [h .qualified_name for h in code_context .helper_functions ]} " )
1005+ assert "multiply" in unused_names , "Expected multiply to be detected as unused"
1006+ assert "process_data" in unused_names , "Expected process_data to be detected as unused"
1007+ assert "subtract" not in unused_names , "Expected subtract not to be detected as unused"
9991008
10001009 # Also test the complete replace_function_and_helpers_with_optimized_code workflow
10011010 # First modify some helper files to simulate optimization changes
@@ -1042,7 +1051,7 @@ def subtract(x, y):
10421051 \" \" \" Subtract function - should be unused.\" \" \"
10431052 return x - y
10441053""" ,
1045- processors_file : processors_file .read_text ()
1054+ processors_file : processors_file .read_text (),
10461055 }
10471056
10481057 # Apply optimization and test reversion
@@ -1051,15 +1060,19 @@ def subtract(x, y):
10511060 # Check main file content
10521061 main_content = main_file .read_text ()
10531062 assert "(n * 2) + (n ** 2)" in main_content , "Entrypoint function should be optimized with inlined calculations"
1054- assert "from math_helpers import add" in main_content , "Imports should be updated to only include used functions"
1063+ assert "from math_helpers import add" in main_content , (
1064+ "Imports should be updated to only include used functions"
1065+ )
10551066
10561067 # Verify that unused helper files are reverted if they contained unused functions that were modified
10571068 math_content = math_file .read_text ()
10581069 assert "def add(x, y):" in math_content , "add function should still exist"
10591070 # If multiply was unused and modified, it should be reverted
10601071 if "multiply" in unused_names :
10611072 assert "return x * y" in math_content , "multiply should be reverted to original if it was unused"
1062- assert "return x * y * 2" not in math_content , "multiply should NOT contain the modified version if it was unused"
1073+ assert "return x * y * 2" not in math_content , (
1074+ "multiply should NOT contain the modified version if it was unused"
1075+ )
10631076
10641077 finally :
10651078 # Cleanup
@@ -1145,9 +1158,6 @@ def entrypoint_function(n):
11451158 # Should detect multiply_numbers and divide_numbers as unused
11461159 unused_names = {uh .qualified_name for uh in unused_helpers }
11471160
1148- print (f"Detected unused helpers: { unused_names } " )
1149- print (f"All helpers in context: { [h .qualified_name for h in code_context .helper_functions ]} " )
1150-
11511161 # Check that multiply_numbers is detected as unused
11521162 assert "multiply_numbers" in unused_names , f"Expected 'multiply_numbers' to be unused, got: { unused_names } "
11531163
@@ -1190,7 +1200,7 @@ def multiply_numbers(x, y):
11901200def divide_numbers(x, y):
11911201 \" \" \" Divide function - should be unused.\" \" \"
11921202 return x / y
1193- """
1203+ """ ,
11941204 }
11951205
11961206 # Apply optimization and test reversion
@@ -1249,7 +1259,7 @@ def multiply_numbers(x, y):
12491259def divide_numbers(x, y):
12501260 \" \" \" Divide function - should be unused.\" \" \"
12511261 return x / y
1252- """
1262+ """ ,
12531263 }
12541264
12551265 # Apply optimization and test reversion
@@ -1399,7 +1409,9 @@ def calculate_class(cls, n):
13991409 original_helper_code = {main_file : main_file .read_text ()}
14001410
14011411 # Apply optimization and test reversion
1402- optimizer .replace_function_and_helpers_with_optimized_code (code_context , optimized_static_code_with_modified_helper , original_helper_code )
1412+ optimizer .replace_function_and_helpers_with_optimized_code (
1413+ code_context , optimized_static_code_with_modified_helper , original_helper_code
1414+ )
14031415
14041416 # Check final file content
14051417 final_content = main_file .read_text ()
0 commit comments