Skip to content

Commit c7941e9

Browse files
generate the mock test context correctly
1 parent 1c7c2b8 commit c7941e9

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

tests/test_code_utils.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
)
2222
from codeflash.code_utils.concolic_utils import clean_concolic_tests
2323
from codeflash.code_utils.coverage_utils import extract_dependent_function, generate_candidates, prepare_coverage_files
24+
from codeflash.models.models import CodeStringsMarkdown
2425

2526

2627
@pytest.fixture
@@ -382,69 +383,76 @@ def mock_code_context():
382383
def test_extract_dependent_function_sync_and_async(mock_code_context):
383384
"""Test extract_dependent_function with both sync and async functions."""
384385
# Test sync function extraction
385-
mock_code_context.testgen_context_code = """
386+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
386387
def main_function():
387388
pass
388389
389390
def helper_function():
390391
pass
391-
"""
392+
```
393+
""")
392394
assert extract_dependent_function("main_function", mock_code_context) == "helper_function"
393395

394396
# Test async function extraction
395-
mock_code_context.testgen_context_code = """
397+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
396398
def main_function():
397399
pass
398400
399401
async def async_helper_function():
400402
pass
401-
"""
403+
```
404+
""")
405+
402406
assert extract_dependent_function("main_function", mock_code_context) == "async_helper_function"
403407

404408

405409
def test_extract_dependent_function_edge_cases(mock_code_context):
406410
"""Test extract_dependent_function edge cases."""
407411
# No dependent functions
408-
mock_code_context.testgen_context_code = """
412+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
409413
def main_function():
410414
pass
411-
"""
415+
```
416+
""")
412417
assert extract_dependent_function("main_function", mock_code_context) is False
413418

414419
# Multiple dependent functions
415-
mock_code_context.testgen_context_code = """
420+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
416421
def main_function():
417422
pass
418-
419423
def helper1():
420424
pass
421425
422426
async def helper2():
423427
pass
424-
"""
428+
```
429+
""")
425430
assert extract_dependent_function("main_function", mock_code_context) is False
426431

427432

428433
def test_extract_dependent_function_mixed_scenarios(mock_code_context):
429434
"""Test extract_dependent_function with mixed sync/async scenarios."""
430435
# Async main with sync helper
431-
mock_code_context.testgen_context_code = """
436+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
432437
async def async_main():
433438
pass
434439
435440
def sync_helper():
436441
pass
437-
"""
442+
```
443+
""")
438444
assert extract_dependent_function("async_main", mock_code_context) == "sync_helper"
439445

440446
# Only async functions
441-
mock_code_context.testgen_context_code = """
447+
mock_code_context.testgen_context = CodeStringsMarkdown.parse_markdown_code("""```python:file.py
442448
async def async_main():
443449
pass
444450
445451
async def async_helper():
446452
pass
447-
"""
453+
```
454+
""")
455+
448456
assert extract_dependent_function("async_main", mock_code_context) == "async_helper"
449457

450458

0 commit comments

Comments
 (0)