Skip to content

Commit 1373696

Browse files
committed
pass
1 parent a4301ce commit 1373696

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

codeflash/code_utils/instrument_existing_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef, test_class_name: str | None =
213213
args=[
214214
ast.JoinedStr(
215215
values=[
216-
ast.Constant(value=get_run_tmp_file("test_return_values_").as_posix()),
216+
ast.Constant(value=get_run_tmp_file("test_return_values_").resolve().as_posix()),
217217
ast.FormattedValue(
218218
value=ast.Name(id="codeflash_iteration", ctx=ast.Load()),
219219
conversion=-1,

tests/test_instrument_all_and_run.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def test_sort():
122122
assert new_test is not None
123123
assert new_test.replace('"', "'") == expected.format(
124124
module_path="code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp",
125-
tmp_dir_path=get_run_tmp_file(Path("test_return_values")),
125+
tmp_dir_path=get_run_tmp_file("test_return_values").as_posix(),
126126
).replace('"', "'")
127127

128128
with test_path.open("w") as f:
@@ -300,16 +300,16 @@ def test_sort():
300300
fto = FunctionToOptimize(
301301
function_name="sorter", parents=[FunctionParent(name="BubbleSorter", type="ClassDef")], file_path=Path(fto_path)
302302
)
303-
with tempfile.NamedTemporaryFile(mode="w") as f:
304-
f.write(code)
305-
f.flush()
303+
with tempfile.TemporaryDirectory() as tempdir:
304+
temp_test_path = Path(tempdir) / "temp_test.py"
305+
temp_test_path.write_text(code)
306306

307307
success, new_test = inject_profiling_into_existing_test(
308-
Path(f.name), [CodePosition(7, 13), CodePosition(12, 13)], fto, Path(f.name).parent, "pytest"
308+
temp_test_path, [CodePosition(7, 13), CodePosition(12, 13)], fto, temp_test_path.parent, "pytest"
309309
)
310310
assert success
311311
assert new_test.replace('"', "'") == expected.format(
312-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
312+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
313313
).replace('"', "'")
314314
tests_root = (Path(__file__).parent.resolve() / "../code_to_optimize/tests/pytest/").resolve()
315315
test_path = tests_root / "test_class_method_behavior_results_temp.py"
@@ -319,7 +319,7 @@ def test_sort():
319319
try:
320320
new_test = expected.format(
321321
module_path="code_to_optimize.tests.pytest.test_class_method_behavior_results_temp",
322-
tmp_dir_path=get_run_tmp_file(Path("test_return_values")),
322+
tmp_dir_path=get_run_tmp_file("test_return_values").as_posix(),
323323
)
324324

325325
with test_path.open("w") as f:

0 commit comments

Comments
 (0)