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