Merge branch 'main' of https://github.com/codeflash-ai/codeflash into exception_2_test
This commit is contained in:
commit
ff39ea1cd3
2 changed files with 14 additions and 8 deletions
|
|
@ -7,10 +7,9 @@ from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codef
|
|||
def run_test(expected_improvement_pct: int) -> bool:
|
||||
config = TestConfig(
|
||||
file_path="bubble_sort.py",
|
||||
function_name="sorter_one_level_depth",
|
||||
coverage_expectations=[
|
||||
CoverageExpectation(function_name="sorter_one_level_depth", expected_coverage=100.0, expected_lines=[2]),
|
||||
CoverageExpectation(function_name="add", expected_coverage=100.0, expected_lines=[44]),
|
||||
CoverageExpectation(function_name="multiply_and_add", expected_coverage=100.0, expected_lines=[41]),
|
||||
CoverageExpectation(function_name="sorter_one_level_depth", expected_coverage=100.0, expected_lines=[2])
|
||||
],
|
||||
)
|
||||
cwd = (
|
||||
|
|
|
|||
|
|
@ -63,23 +63,25 @@ def validate_coverage(stdout: str, expectations: list[CoverageExpectation]) -> b
|
|||
assert coverage_match, f"Failed to find coverage data for {expect.function_name}"
|
||||
|
||||
coverage = float(coverage_match.group(1))
|
||||
assert coverage == expect.expected_coverage, f"Coverage was {coverage} instead of {expect.expected_coverage}"
|
||||
assert (
|
||||
coverage == expect.expected_coverage
|
||||
), f"Coverage was {coverage} instead of {expect.expected_coverage} for function: {expect.function_name}"
|
||||
|
||||
executed_lines = list(map(int, coverage_match.group(2).split(", ")))
|
||||
assert (
|
||||
executed_lines == expect.expected_lines
|
||||
), f"Executed lines were {executed_lines} instead of {expect.expected_lines}"
|
||||
), f"Executed lines were {executed_lines} instead of {expect.expected_lines} for function: {expect.function_name}"
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def run_codeflash_command(cwd: pathlib.Path, config: TestConfig, expected_improvement_pct: int) -> bool:
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logging.info("If you see this, logging is working!")
|
||||
# print("Debug")
|
||||
if config.trace_mode:
|
||||
return run_trace_test(cwd, config, expected_improvement_pct)
|
||||
|
||||
path_to_file = cwd / config.file_path
|
||||
file_contents = path_to_file.read_text("utf-8")
|
||||
test_root = cwd / "tests" / (config.test_framework or "")
|
||||
command = build_command(cwd, config, test_root)
|
||||
|
||||
|
|
@ -95,7 +97,12 @@ def run_codeflash_command(cwd: pathlib.Path, config: TestConfig, expected_improv
|
|||
return_code = process.wait()
|
||||
stdout = "".join(output)
|
||||
|
||||
return validate_output(stdout, return_code, expected_improvement_pct, config)
|
||||
if not validate_output(stdout, return_code, expected_improvement_pct, config):
|
||||
# Write original file contents back to file
|
||||
path_to_file.write_text(file_contents, "utf-8")
|
||||
logging.info("Codeflash run did not meet expected requirements for testing, reverting file changes.")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def build_command(cwd: pathlib.Path, config: TestConfig, test_root: pathlib.Path) -> list[str]:
|
||||
|
|
|
|||
Loading…
Reference in a new issue