Skip to content

Commit 5830d98

Browse files
committed
pass
1 parent f30e4aa commit 5830d98

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
@@ -212,7 +212,7 @@ def visit_FunctionDef(self, node: ast.FunctionDef, test_class_name: str | None =
212212
args=[
213213
ast.JoinedStr(
214214
values=[
215-
ast.Constant(value=get_run_tmp_file("test_return_values_").as_posix()),
215+
ast.Constant(value=get_run_tmp_file("test_return_values_").resolve().as_posix()),
216216
ast.FormattedValue(
217217
value=ast.Name(id="codeflash_iteration", ctx=ast.Load()),
218218
conversion=-1,

tests/test_instrument_all_and_run.py

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

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

306306
success, new_test = inject_profiling_into_existing_test(
307-
Path(f.name), [CodePosition(7, 13), CodePosition(12, 13)], fto, Path(f.name).parent, "pytest"
307+
temp_test_path, [CodePosition(7, 13), CodePosition(12, 13)], fto, temp_test_path.parent, "pytest"
308308
)
309309
assert success
310310
assert new_test.replace('"', "'") == expected.format(
311-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
311+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
312312
).replace('"', "'")
313313
tests_root = (Path(__file__).parent.resolve() / "../code_to_optimize/tests/pytest/").resolve()
314314
test_path = tests_root / "test_class_method_behavior_results_temp.py"
@@ -318,7 +318,7 @@ def test_sort():
318318
try:
319319
new_test = expected.format(
320320
module_path="code_to_optimize.tests.pytest.test_class_method_behavior_results_temp",
321-
tmp_dir_path=get_run_tmp_file(Path("test_return_values")),
321+
tmp_dir_path=get_run_tmp_file("test_return_values").as_posix(),
322322
)
323323

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

0 commit comments

Comments
 (0)