Skip to content

Commit 8f8c127

Browse files
committed
pass 3
1 parent 86199c4 commit 8f8c127

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
@@ -266,20 +266,21 @@ def test_prepare_image_for_yolo():
266266
assert compare_results(return_val_1, ret)
267267
codeflash_con.close()
268268
"""
269-
with tempfile.NamedTemporaryFile(mode="w") as f:
270-
f.write(code)
271-
f.flush()
272-
func = FunctionToOptimize(function_name="prepare_image_for_yolo", parents=[], file_path=Path("module.py"))
269+
with tempfile.TemporaryDirectory() as tempdir:
270+
temp_file_path = Path(tempdir) / "temp_test.py"
271+
with temp_file_path.open("w") as f:
272+
f.write(code)
273+
func = FunctionToOptimize(function_name="prepare_image_for_yolo", parents=[], file_path=temp_file_path)
273274
original_cwd = Path.cwd()
274275
run_cwd = Path(__file__).parent.parent.resolve()
275276
os.chdir(run_cwd)
276277
success, new_test = inject_profiling_into_existing_test(
277-
Path(f.name), [CodePosition(10, 14)], func, Path(f.name).parent, "pytest"
278+
temp_file_path, [CodePosition(10, 14)], func, temp_file_path.parent, "pytest"
278279
)
279280
os.chdir(original_cwd)
280281
assert success
281282
assert new_test == expected.format(
282-
module_path=Path(f.name).name, tmp_dir_path=get_run_tmp_file(Path("test_return_values"))
283+
module_path="temp_test", tmp_dir_path=get_run_tmp_file("test_return_values").as_posix()
283284
)
284285

285286

@@ -379,7 +380,7 @@ def test_sort():
379380
assert new_test is not None
380381
assert new_test.replace('"', "'") == expected.format(
381382
module_path="code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp",
382-
tmp_dir_path=get_run_tmp_file(Path("test_return_values")),
383+
tmp_dir_path=get_run_tmp_file("test_return_values").as_posix(),
383384
).replace('"', "'")
384385

385386
success, new_perf_test = inject_profiling_into_existing_test(

0 commit comments

Comments
 (0)