codeflash/tests/test_merge_test_results.py
Alvin Ryanputra d6bcdbdc49
Some checks failed
CodeFlash / Optimize new Python code (pull_request) Failing after 1s
end-to-end-test / bubble-sort-optimization-pytest-no-git (pull_request) Failing after 2s
end-to-end-test / bubble-sort-optimization-unittest (pull_request) Failing after 1s
Coverage E2E / end-to-end-test-coverage (pull_request) Failing after 2s
end-to-end-test / init-optimization (pull_request) Failing after 2s
end-to-end-test / tracer-replay (pull_request) Failing after 2s
end-to-end-test / topological-sort-optimization (pull_request) Failing after 2s
unit-tests / unit-tests (3.11.6) (pull_request) Failing after 2s
unit-tests / unit-tests (3.9.18) (pull_request) Failing after 1s
end-to-end-test / futurehouse-structure (pull_request) Failing after 2s
Mypy Type Checking for CLI / type-check-cli (pull_request) Failing after 2s
/ Run pr agent on every pull request, respond to user comments (pull_request) Failing after 1s
unit-tests / unit-tests (3.10.13) (pull_request) Failing after 2s
unit-tests / unit-tests (3.12.1) (pull_request) Failing after 1s
unit-tests / unit-tests (3.13.0) (pull_request) Failing after 2s
organized imports
2025-03-28 15:26:27 -07:00

291 lines
10 KiB
Python

from codeflash.models.models import FunctionTestInvocation, InvocationId, TestResults, TestType
from codeflash.verification.parse_test_output import merge_test_results
def test_merge_test_results_1():
test_results_xml = TestResults()
test_results_xml.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="5",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=None,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_xml.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="8",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=458,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_xml.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="11",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=14125,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_bin = TestResults()
test_results_bin.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="5",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=667,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_bin.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="8",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=458,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_bin.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="11",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=14125,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
expected_merged_results = TestResults()
expected_merged_results.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="5",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=667,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
expected_merged_results.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="8",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=458,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
expected_merged_results.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="11",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=14125,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
merged_results = merge_test_results(
xml_test_results=test_results_xml, bin_test_results=test_results_bin, test_framework="unittest"
)
assert merged_results == expected_merged_results
test_results_xml_single = TestResults()
test_results_xml_single.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name="TestPigLatin",
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id=None,
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=None,
test_framework="unittest",
test_type=TestType.EXISTING_UNIT_TEST,
return_value=None,
timed_out=False,
loop_index=1,
)
)
merged_results = merge_test_results(
xml_test_results=test_results_xml_single, bin_test_results=test_results_bin, test_framework="unittest"
)
assert merged_results == expected_merged_results
merged_results = merge_test_results(
xml_test_results=test_results_xml_single, bin_test_results=TestResults(), test_framework="unittest"
)
assert merged_results == test_results_xml_single
merged_results = merge_test_results(
xml_test_results=TestResults(), bin_test_results=test_results_bin, test_framework="unittest"
)
assert merged_results == TestResults() # XML Results should always have better coverage than bin results
test_results_xml_pytest = TestResults()
test_results_xml_pytest.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name=None,
test_function_name="test_sort",
function_getting_tested="",
iteration_id=None,
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=None,
test_framework="pytest",
test_type=TestType.GENERATED_REGRESSION,
return_value=None,
timed_out=False,
loop_index=1,
)
)
test_results_bin_pytest = TestResults()
test_results_bin_pytest.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name=None,
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="5",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=667,
test_framework="pytest",
test_type=TestType.GENERATED_REGRESSION,
return_value=[2],
timed_out=False,
loop_index=1,
)
)
test_results_bin_pytest.add(
FunctionTestInvocation(
id=InvocationId(
test_module_path="code_to_optimize.tests.unittest.test_bubble_sort",
test_class_name=None,
test_function_name="test_sort",
function_getting_tested="sorter",
iteration_id="8",
),
file_name="/tmp/tests/unittest/test_bubble_sort__perfinstrumented.py",
did_pass=True,
runtime=458,
test_framework="pytest",
test_type=TestType.GENERATED_REGRESSION,
return_value=[3],
timed_out=False,
loop_index=1,
)
)
merged_results = merge_test_results(
xml_test_results=test_results_xml_pytest, bin_test_results=test_results_bin_pytest, test_framework="unittest"
)
assert merged_results == test_results_bin_pytest