Skip to content

Commit b74509a

Browse files
committed
e2e test
1 parent c10981f commit b74509a

File tree

4 files changed

+50
-4
lines changed

4 files changed

+50
-4
lines changed

codeflash/code_utils/code_utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ def custom_addopts() -> None:
2828
with Path.open(pyproject_file, encoding="utf-8") as f:
2929
original_content = f.read()
3030
data = tomlkit.parse(original_content)
31-
3231
# Backup original addopts
3332
original_addopts = data.get("tool", {}).get("pytest", {}).get("ini_options", {}).get("addopts", "")
3433
# nothing to do if no addopts present
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import os
2+
from pathlib import Path
3+
4+
from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries
5+
import tomlkit
6+
7+
8+
def run_test(expected_improvement_pct: int) -> bool:
9+
try:
10+
# Modify Pyproject file
11+
with Path.open((Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), encoding="utf-8") as f:
12+
original_content = f.read()
13+
data = tomlkit.parse(original_content)
14+
data["tool"]["pytest"] = {}
15+
data["tool"]["pytest"]["ini_options"] = {}
16+
data["tool"]["pytest"]["ini_options"]["addopts"] = ["-n=auto", "-n", "1", "-n 1", "-n 1", "-n auto"]
17+
with Path.open((Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), "w", encoding="utf-8") as f:
18+
f.write(tomlkit.dumps(data))
19+
20+
config = TestConfig(
21+
file_path="bubble_sort.py",
22+
function_name="sorter",
23+
test_framework="pytest",
24+
min_improvement_x=1.0,
25+
coverage_expectations=[
26+
CoverageExpectation(
27+
function_name="sorter", expected_coverage=100.0, expected_lines=[2, 3, 4, 5, 6, 7, 8, 9, 10]
28+
)
29+
],
30+
)
31+
cwd = (Path(__file__).parent.parent.parent / "code_to_optimize").resolve()
32+
return run_codeflash_command(
33+
cwd,
34+
config,
35+
expected_improvement_pct,
36+
['print("codeflash stdout: Sorting list")', 'print(f"result: {arr}")'],
37+
)
38+
finally:
39+
with Path.open(Path("pyproject.toml"), "w", encoding="utf-8") as f:
40+
f.write(original_content)
41+
42+
43+
if __name__ == "__main__":
44+
exit(run_with_retries(run_test, int(os.getenv("EXPECTED_IMPROVEMENT_PCT", 100))))

tests/scripts/end_to_end_test_tracer_replay.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@ def run_test(expected_improvement_pct: int) -> bool:
1010
min_improvement_x=0.1,
1111
expected_unit_tests=1,
1212
coverage_expectations=[
13-
CoverageExpectation(function_name="funcA", expected_coverage=100.0, expected_lines=[5, 6, 7, 8, 10, 13]),
13+
CoverageExpectation(function_name="funcA", expected_coverage=100.0, expected_lines=[5, 6, 7, 8, 10, 13])
1414
],
1515
)
1616
cwd = (
1717
pathlib.Path(__file__).parent.parent.parent / "code_to_optimize" / "code_directories" / "simple_tracer_e2e"
1818
).resolve()
1919
return run_codeflash_command(cwd, config, expected_improvement_pct)
2020

21+
2122
if __name__ == "__main__":
2223
exit(run_with_retries(run_test, int(os.getenv("EXPECTED_IMPROVEMENT_PCT", 10))))

tests/scripts/end_to_end_test_utilities.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ def run_codeflash_command(
117117
return validated
118118

119119

120-
def build_command(cwd: pathlib.Path, config: TestConfig, test_root: pathlib.Path, benchmarks_root:pathlib.Path|None = None) -> list[str]:
120+
def build_command(
121+
cwd: pathlib.Path, config: TestConfig, test_root: pathlib.Path, benchmarks_root: pathlib.Path | None = None
122+
) -> list[str]:
121123
python_path = "../../../codeflash/main.py" if "code_directories" in str(cwd) else "../codeflash/main.py"
122124

123125
base_command = ["python", python_path, "--file", config.file_path, "--no-pr"]
@@ -251,4 +253,4 @@ def run_with_retries(test_func, *args, **kwargs) -> bool:
251253
logging.error("Test failed after all retries")
252254
return 1
253255

254-
return 1
256+
return 1

0 commit comments

Comments
 (0)