Skip to content

Commit 4fac1e2

Browse files
committed
increase test coverage
1 parent 075a2ae commit 4fac1e2

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

tests/test_unused_helper_revert.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from codeflash.models.models import CodeStringsMarkdown
1010
from codeflash.optimization.function_optimizer import FunctionOptimizer
1111
from codeflash.verification.verification_utils import TestConfig
12+
from codeflash.context.unused_definition_remover import revert_unused_helper_functions
13+
1214

1315

1416
@pytest.fixture
@@ -225,6 +227,15 @@ def helper_function_2(x):
225227
def test_no_unused_helpers_no_revert(temp_project):
226228
"""Test that when all helpers are still used, nothing is reverted."""
227229
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"
228239

229240
# Optimized version that still calls both helpers
230241
optimized_code = """
@@ -308,17 +319,23 @@ def helper_function_1(x):
308319
def helper_function_2(x):
309320
\"\"\"Second helper function.\"\"\"
310321
return x * 3
322+
323+
def helper_function_1(y): # Duplicate name to test line 575
324+
\"\"\"Overloaded helper function.\"\"\"
325+
return y + 10
311326
""")
312327

313-
# Optimized version that only calls one helper
328+
# Optimized version that only calls one helper with aliased import
314329
optimized_code = """
315330
```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
317333
318334
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
322339
```
323340
"""
324341

0 commit comments

Comments
 (0)