@@ -356,10 +356,9 @@ def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
356356            lifespan=self.__duration__, 
357357        ) 
358358''' 
359-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
360-         f .write (code )
361-         f .flush ()
362-         file_path  =  Path (f .name ).resolve ()
359+     with  tempfile .TemporaryDirectory () as  temp_dir :
360+         file_path  =  Path (temp_dir ) /  "test.py" 
361+         file_path .write_text (code )
363362        opt  =  Optimizer (
364363            Namespace (
365364                project_root = file_path .parent .resolve (),
@@ -368,7 +367,7 @@ def __call__(self, *args: _P.args, **kwargs: _P.kwargs) -> _R:
368367                test_framework = "pytest" ,
369368                pytest_cmd = "pytest" ,
370369                experiment_id = None ,
371-                 test_project_root = Path (). resolve (),
370+                 test_project_root = Path . cwd (),
372371            )
373372        )
374373        function_to_optimize  =  FunctionToOptimize (
@@ -557,10 +556,9 @@ def __repr__(self):
557556    def helper_method(self): 
558557        return self.x 
559558""" 
560-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
561-         f .write (code )
562-         f .flush ()
563-         file_path  =  Path (f .name ).resolve ()
559+     with  tempfile .TemporaryDirectory () as  temp_dir :
560+         file_path  =  Path (temp_dir ) /  "test.py" 
561+         file_path .write_text (code )
564562        opt  =  Optimizer (
565563            Namespace (
566564                project_root = file_path .parent .resolve (),
@@ -569,7 +567,7 @@ def helper_method(self):
569567                test_framework = "pytest" ,
570568                pytest_cmd = "pytest" ,
571569                experiment_id = None ,
572-                 test_project_root = Path (). resolve (),
570+                 test_project_root = Path . cwd (),
573571            )
574572        )
575573        function_to_optimize  =  FunctionToOptimize (
@@ -637,10 +635,9 @@ def __repr__(self):
637635    def helper_method(self): 
638636        return self.x 
639637""" 
640-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
641-         f .write (code )
642-         f .flush ()
643-         file_path  =  Path (f .name ).resolve ()
638+     with  tempfile .TemporaryDirectory () as  temp_dir :
639+         file_path  =  Path (temp_dir ) /  "test.py" 
640+         file_path .write_text (code )
644641        opt  =  Optimizer (
645642            Namespace (
646643                project_root = file_path .parent .resolve (),
@@ -649,7 +646,7 @@ def helper_method(self):
649646                test_framework = "pytest" ,
650647                pytest_cmd = "pytest" ,
651648                experiment_id = None ,
652-                 test_project_root = Path (). resolve (),
649+                 test_project_root = Path . cwd (),
653650            )
654651        )
655652        function_to_optimize  =  FunctionToOptimize (
@@ -717,10 +714,9 @@ def __repr__(self):
717714    def helper_method(self): 
718715        return self.x 
719716""" 
720-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
721-         f .write (code )
722-         f .flush ()
723-         file_path  =  Path (f .name ).resolve ()
717+     with  tempfile .TemporaryDirectory () as  temp_dir :
718+         file_path  =  Path (temp_dir ) /  "test.py" 
719+         file_path .write_text (code )
724720        opt  =  Optimizer (
725721            Namespace (
726722                project_root = file_path .parent .resolve (),
@@ -729,7 +725,7 @@ def helper_method(self):
729725                test_framework = "pytest" ,
730726                pytest_cmd = "pytest" ,
731727                experiment_id = None ,
732-                 test_project_root = Path (). resolve (),
728+                 test_project_root = Path . cwd (),
733729            )
734730        )
735731        function_to_optimize  =  FunctionToOptimize (
@@ -787,10 +783,9 @@ def __repr__(self):
787783    def helper_method(self): 
788784        return self.x 
789785""" 
790-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
791-         f .write (code )
792-         f .flush ()
793-         file_path  =  Path (f .name ).resolve ()
786+     with  tempfile .TemporaryDirectory () as  temp_dir :
787+         file_path  =  Path (temp_dir ) /  "test.py" 
788+         file_path .write_text (code )
794789        opt  =  Optimizer (
795790            Namespace (
796791                project_root = file_path .parent .resolve (),
@@ -838,10 +833,9 @@ def __repr__(self):
838833    def helper_method(self): 
839834        return self.x 
840835""" 
841-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
842-         f .write (code )
843-         f .flush ()
844-         file_path  =  Path (f .name ).resolve ()
836+     with  tempfile .TemporaryDirectory () as  temp_dir :
837+         file_path  =  Path (temp_dir ) /  "test.py" 
838+         file_path .write_text (code )
845839        opt  =  Optimizer (
846840            Namespace (
847841                project_root = file_path .parent .resolve (),
@@ -1272,10 +1266,9 @@ def target_method(self):
12721266def outside_method(): 
12731267    return 1 
12741268""" 
1275-     with  tempfile .NamedTemporaryFile (mode = "w" ) as  f :
1276-         f .write (code )
1277-         f .flush ()
1278-         file_path  =  Path (f .name ).resolve ()
1269+     with  tempfile .TemporaryDirectory () as  temp_dir :
1270+         file_path  =  Path (temp_dir ) /  "test.py" 
1271+         file_path .write_text (code )
12791272        opt  =  Optimizer (
12801273            Namespace (
12811274                project_root = file_path .parent .resolve (),
0 commit comments