@@ -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