Skip to content

Commit 9db9eec

Browse files
committed
pass 3
1 parent 827dd54 commit 9db9eec

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

tests/test_instrument_codeflash_capture.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def target_function(self):
2222
2323
class MyClass:
2424
25-
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=True)
25+
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file("test_return_values").as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=True)
2626
def __init__(self):
2727
self.x = 1
2828
@@ -86,7 +86,7 @@ def target_function(self):
8686
8787
class MyClass(ParentClass):
8888
89-
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=True)
89+
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=True)
9090
def __init__(self, *args, **kwargs):
9191
super().__init__(*args, **kwargs)
9292
@@ -128,7 +128,7 @@ def helper(self):
128128
129129
class MyClass:
130130
131-
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=True)
131+
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=True)
132132
def __init__(self):
133133
self.x = 1
134134
@@ -184,7 +184,7 @@ def helper(self):
184184
185185
class MyClass:
186186
187-
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=True)
187+
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=True)
188188
def __init__(self):
189189
self.x = 1
190190
@@ -197,7 +197,7 @@ def target_function(self):
197197
198198
class HelperClass:
199199
200-
@codeflash_capture(function_name='HelperClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=False)
200+
@codeflash_capture(function_name='HelperClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=False)
201201
def __init__(self):
202202
self.y = 1
203203
@@ -271,7 +271,7 @@ def another_helper(self):
271271
272272
class MyClass:
273273
274-
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=True)
274+
@codeflash_capture(function_name='MyClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=True)
275275
def __init__(self):
276276
self.x = 1
277277
@@ -289,7 +289,7 @@ def target_function(self):
289289
290290
class HelperClass1:
291291
292-
@codeflash_capture(function_name='HelperClass1.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=False)
292+
@codeflash_capture(function_name='HelperClass1.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=False)
293293
def __init__(self):
294294
self.y = 1
295295
@@ -304,7 +304,7 @@ def helper1(self):
304304
305305
class HelperClass2:
306306
307-
@codeflash_capture(function_name='HelperClass2.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=False)
307+
@codeflash_capture(function_name='HelperClass2.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=False)
308308
def __init__(self):
309309
self.z = 2
310310
@@ -313,7 +313,7 @@ def helper2(self):
313313
314314
class AnotherHelperClass:
315315
316-
@codeflash_capture(function_name='AnotherHelperClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values"))!s}', tests_root='{test_path.parent!s}', is_fto=False)
316+
@codeflash_capture(function_name='AnotherHelperClass.__init__', tmp_dir_path='{get_run_tmp_file(Path("test_return_values")).as_posix()}', tests_root='{test_path.parent.as_posix()}', is_fto=False)
317317
def __init__(self, *args, **kwargs):
318318
super().__init__(*args, **kwargs)
319319

tests/test_instrument_tests.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -259,20 +259,21 @@ def test_prepare_image_for_yolo():
259259
assert compare_results(return_val_1, ret)
260260
codeflash_con.close()
261261
"""
262-
with tempfile.NamedTemporaryFile(mode="w") as f:
263-
f.write(code)
264-
f.flush()
265-
func = FunctionToOptimize(function_name="prepare_image_for_yolo", parents=[], file_path=Path("module.py"))
262+
with tempfile.TemporaryDirectory() as tempdir:
263+
temp_file_path = Path(tempdir) / "temp_test.py"
264+
with temp_file_path.open("w") as f:
265+
f.write(code)
266+
func = FunctionToOptimize(function_name="prepare_image_for_yolo", parents=[], file_path=temp_file_path)
266267
original_cwd = Path.cwd()
267268
run_cwd = Path(__file__).parent.parent.resolve()
268269
os.chdir(run_cwd)
269270
success, new_test = inject_profiling_into_existing_test(
270-
Path(f.name), [CodePosition(10, 14)], func, Path(f.name).parent, "pytest"
271+
temp_file_path, [CodePosition(10, 14)], func, temp_file_path.parent, "pytest"
271272
)
272273
os.chdir(original_cwd)
273274
assert success
274275
assert new_test == expected.format(
275-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
276+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
276277
)
277278

278279

@@ -372,7 +373,7 @@ def test_sort():
372373
assert new_test is not None
373374
assert new_test.replace('"', "'") == expected.format(
374375
module_path="code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp",
375-
tmp_dir_path=get_run_tmp_file(Path("test_return_values")),
376+
tmp_dir_path=get_run_tmp_file("test_return_values").as_posix(),
376377
).replace('"', "'")
377378

378379
success, new_perf_test = inject_profiling_into_existing_test(

0 commit comments

Comments
 (0)