|
16 | 16 | import pytest |
17 | 17 |
|
18 | 18 | from codeflash.either import Failure, Success |
19 | | -from codeflash.models.models import FunctionTestInvocation, InvocationId, TestResults, TestType |
| 19 | +from codeflash.models.models import FunctionTestInvocation, InvocationId, TestDiffScope, TestResults, TestType |
20 | 20 | from codeflash.verification.comparator import ( |
21 | 21 | PYTEST_TEMP_PATH_PATTERN, |
22 | 22 | PYTHON_TEMPFILE_PATTERN, |
@@ -2999,6 +2999,60 @@ def test_compare_results_fn(): |
2999 | 2999 | assert not match |
3000 | 3000 |
|
3001 | 3001 |
|
| 3002 | +def test_compare_results_detects_stdout_mismatch_when_candidate_stdout_is_empty() -> None: |
| 3003 | + original_results = TestResults() |
| 3004 | + original_results.add( |
| 3005 | + FunctionTestInvocation( |
| 3006 | + id=InvocationId( |
| 3007 | + test_module_path="test_module_path", |
| 3008 | + test_class_name="test_class_name", |
| 3009 | + test_function_name="test_function_name", |
| 3010 | + function_getting_tested="function_getting_tested", |
| 3011 | + iteration_id="0", |
| 3012 | + ), |
| 3013 | + file_name=Path("file_name"), |
| 3014 | + did_pass=True, |
| 3015 | + runtime=5, |
| 3016 | + test_framework="pytest", |
| 3017 | + test_type=TestType.EXISTING_UNIT_TEST, |
| 3018 | + return_value=[0, 1, 2], |
| 3019 | + timed_out=False, |
| 3020 | + loop_index=1, |
| 3021 | + stdout="codeflash stdout: Sorting list\nresult: [0, 1, 2]\n", |
| 3022 | + ) |
| 3023 | + ) |
| 3024 | + |
| 3025 | + candidate_results = TestResults() |
| 3026 | + candidate_results.add( |
| 3027 | + FunctionTestInvocation( |
| 3028 | + id=InvocationId( |
| 3029 | + test_module_path="test_module_path", |
| 3030 | + test_class_name="test_class_name", |
| 3031 | + test_function_name="test_function_name", |
| 3032 | + function_getting_tested="function_getting_tested", |
| 3033 | + iteration_id="0", |
| 3034 | + ), |
| 3035 | + file_name=Path("file_name"), |
| 3036 | + did_pass=True, |
| 3037 | + runtime=5, |
| 3038 | + test_framework="pytest", |
| 3039 | + test_type=TestType.EXISTING_UNIT_TEST, |
| 3040 | + return_value=[0, 1, 2], |
| 3041 | + timed_out=False, |
| 3042 | + loop_index=1, |
| 3043 | + stdout="", |
| 3044 | + ) |
| 3045 | + ) |
| 3046 | + |
| 3047 | + match, diffs = compare_test_results(original_results, candidate_results) |
| 3048 | + |
| 3049 | + assert not match |
| 3050 | + assert len(diffs) == 1 |
| 3051 | + assert diffs[0].scope == TestDiffScope.STDOUT |
| 3052 | + assert diffs[0].original_value == "codeflash stdout: Sorting list\nresult: [0, 1, 2]\n" |
| 3053 | + assert diffs[0].candidate_value == "" |
| 3054 | + |
| 3055 | + |
3002 | 3056 | def test_exceptions(): |
3003 | 3057 | type_error = TypeError("This is a type error") |
3004 | 3058 |
|
|
0 commit comments