|
1 | 1 | import os |
2 | 2 | import pathlib |
| 3 | +import tomlkit |
3 | 4 |
|
4 | 5 | from end_to_end_test_utilities import CoverageExpectation, TestConfig, run_codeflash_command, run_with_retries |
5 | 6 |
|
6 | 7 |
|
7 | 8 | def run_test(expected_improvement_pct: int) -> bool: |
8 | | - config = TestConfig( |
9 | | - file_path="topological_sort.py", |
10 | | - function_name="Graph.topologicalSort", |
11 | | - test_framework="pytest", |
12 | | - min_improvement_x=0.05, |
13 | | - coverage_expectations=[ |
14 | | - CoverageExpectation( |
15 | | - function_name="Graph.topologicalSort", expected_coverage=100.0, expected_lines=[24, 25, 26, 27, 28, 29] |
16 | | - ) |
17 | | - ], |
18 | | - ) |
19 | | - cwd = (pathlib.Path(__file__).parent.parent.parent / "code_to_optimize").resolve() |
20 | | - return run_codeflash_command(cwd, config, expected_improvement_pct) |
| 9 | + try: |
| 10 | + # Modify Pyproject file |
| 11 | + with pathlib.Path.open((pathlib.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 pathlib.Path.open((pathlib.Path(__file__).parent.parent.parent / "pyproject.toml").resolve(), "w", encoding="utf-8") as f: |
| 18 | + f.write(tomlkit.dumps(data)) |
| 19 | + config = TestConfig( |
| 20 | + file_path="topological_sort.py", |
| 21 | + function_name="Graph.topologicalSort", |
| 22 | + test_framework="pytest", |
| 23 | + min_improvement_x=0.05, |
| 24 | + coverage_expectations=[ |
| 25 | + CoverageExpectation( |
| 26 | + function_name="Graph.topologicalSort", expected_coverage=100.0, expected_lines=[24, 25, 26, 27, 28, 29] |
| 27 | + ) |
| 28 | + ], |
| 29 | + ) |
| 30 | + cwd = (pathlib.Path(__file__).parent.parent.parent / "code_to_optimize").resolve() |
| 31 | + return run_codeflash_command(cwd, config, expected_improvement_pct) |
| 32 | + finally: |
| 33 | + with pathlib.Path.open(pathlib.Path("pyproject.toml"), "w", encoding="utf-8") as f: |
| 34 | + f.write(original_content) |
| 35 | + |
21 | 36 |
|
22 | 37 |
|
23 | 38 | if __name__ == "__main__": |
|
0 commit comments