|
9 | 9 | from codeflash.models.models import CodeStringsMarkdown |
10 | 10 | from codeflash.optimization.function_optimizer import FunctionOptimizer |
11 | 11 | from codeflash.verification.verification_utils import TestConfig |
| 12 | +from codeflash.context.unused_definition_remover import revert_unused_helper_functions |
| 13 | + |
12 | 14 |
|
13 | 15 |
|
14 | 16 | @pytest.fixture |
@@ -225,6 +227,15 @@ def helper_function_2(x): |
225 | 227 | def test_no_unused_helpers_no_revert(temp_project): |
226 | 228 | """Test that when all helpers are still used, nothing is reverted.""" |
227 | 229 | temp_dir, main_file, test_cfg = temp_project |
| 230 | + |
| 231 | + |
| 232 | + # Store original content to verify nothing changes |
| 233 | + original_content = main_file.read_text() |
| 234 | + |
| 235 | + revert_unused_helper_functions(temp_dir, [], {}) |
| 236 | + |
| 237 | + # Verify the file content remains unchanged |
| 238 | + assert main_file.read_text() == original_content, "File should remain unchanged when no helpers to revert" |
228 | 239 |
|
229 | 240 | # Optimized version that still calls both helpers |
230 | 241 | optimized_code = """ |
@@ -308,17 +319,23 @@ def helper_function_1(x): |
308 | 319 | def helper_function_2(x): |
309 | 320 | \"\"\"Second helper function.\"\"\" |
310 | 321 | return x * 3 |
| 322 | +
|
| 323 | +def helper_function_1(y): # Duplicate name to test line 575 |
| 324 | + \"\"\"Overloaded helper function.\"\"\" |
| 325 | + return y + 10 |
311 | 326 | """) |
312 | 327 |
|
313 | | - # Optimized version that only calls one helper |
| 328 | + # Optimized version that only calls one helper with aliased import |
314 | 329 | optimized_code = """ |
315 | 330 | ```python:main.py |
316 | | -from helpers import helper_function_1 |
| 331 | +from helpers import helper_function_1 as h1 |
| 332 | +import helpers as h_module |
317 | 333 |
|
318 | 334 | def entrypoint_function(n): |
319 | | - \"\"\"Optimized function that only calls one helper.\"\"\" |
320 | | - result1 = helper_function_1(n) |
321 | | - return result1 + n * 3 # Inlined helper_function_2 |
| 335 | + \"\"\"Optimized function that only calls one helper with aliasing.\"\"\" |
| 336 | + result1 = h1(n) # Using aliased import |
| 337 | + # Inlined helper_function_2 functionality: n * 3 |
| 338 | + return result1 + n * 3 # Fully inlined helper_function_2 |
322 | 339 | ``` |
323 | 340 | """ |
324 | 341 |
|
|
0 commit comments