|
17 | 17 | is_class_defined_in_file, |
18 | 18 | module_name_from_file_path, |
19 | 19 | path_belongs_to_site_packages, |
20 | | - has_any_async_functions, |
| 20 | + validate_python_code, |
21 | 21 | ) |
22 | 22 | from codeflash.code_utils.concolic_utils import clean_concolic_tests |
23 | 23 | from codeflash.code_utils.coverage_utils import generate_candidates, prepare_coverage_files |
@@ -445,25 +445,41 @@ def test_Grammar_copy(): |
445 | 445 | assert cleaned_code == expected_cleaned_code.strip() |
446 | 446 |
|
447 | 447 |
|
448 | | -def test_has_any_async_functions_with_async_code() -> None: |
449 | | - code = """ |
450 | | -def normal_function(): |
451 | | - pass |
| 448 | +def test_validate_python_code_valid() -> None: |
| 449 | + code = "def hello():\n return 'world'" |
| 450 | + result = validate_python_code(code) |
| 451 | + assert result == code |
452 | 452 |
|
453 | | -async def async_function(): |
454 | | - pass |
455 | | -""" |
456 | | - result = has_any_async_functions(code) |
457 | | - assert result is True |
458 | 453 |
|
| 454 | +def test_validate_python_code_invalid() -> None: |
| 455 | + code = "def hello(:\n return 'world'" |
| 456 | + with pytest.raises(ValueError, match="Invalid Python code"): |
| 457 | + validate_python_code(code) |
459 | 458 |
|
460 | | -def test_has_any_async_functions_without_async_code() -> None: |
461 | | - code = """ |
462 | | -def normal_function(): |
463 | | - pass |
464 | 459 |
|
465 | | -def another_function(): |
466 | | - pass |
| 460 | +def test_validate_python_code_empty() -> None: |
| 461 | + code = "" |
| 462 | + result = validate_python_code(code) |
| 463 | + assert result == code |
| 464 | + |
| 465 | + |
| 466 | +def test_validate_python_code_complex_invalid() -> None: |
| 467 | + code = "if True\n print('missing colon')" |
| 468 | + with pytest.raises(ValueError, match="Invalid Python code.*line 1.*column 8"): |
| 469 | + validate_python_code(code) |
| 470 | + |
| 471 | + |
| 472 | +def test_validate_python_code_valid_complex() -> None: |
| 473 | + code = """ |
| 474 | +def calculate(a, b): |
| 475 | + if a > b: |
| 476 | + return a + b |
| 477 | + else: |
| 478 | + return a * b |
| 479 | + |
| 480 | +class MyClass: |
| 481 | + def __init__(self): |
| 482 | + self.value = 42 |
467 | 483 | """ |
468 | | - result = has_any_async_functions(code) |
469 | | - assert result is False |
| 484 | + result = validate_python_code(code) |
| 485 | + assert result == code |
0 commit comments