@@ -315,7 +315,7 @@ def codeflash_wrap(
315315''' 
316316    if  sys .version_info  <  (3 , 12 ):
317317        expected  +=  """    print( 
318-         fr "!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!" 
318+         f "!######{{test_module_name}}:{{(test_class_name + '.' if test_class_name else '')}}{{test_name}}:{{function_name}}:{{loop_index}}:{{invocation_id}}######!" 
319319    )""" 
320320    else :
321321        expected  +=  """    print( 
@@ -545,91 +545,91 @@ def test_sort():
545545            testing_time = 0.1 ,
546546        )
547547        assert  test_results [0 ].id .function_getting_tested  ==  "sorter" 
548-         #  assert test_results[0].id.iteration_id == "1_0"
549-         #  assert test_results[0].id.test_class_name is None
550-         #  assert test_results[0].id.test_function_name == "test_sort"
551-         #  assert (
552-         #      test_results[0].id.test_module_path
553-         #      == "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp"
554-         #  )
555- #          assert test_results[0].runtime > 0
556- #          assert test_results[0].did_pass
557- #          assert test_results[0].return_value == ([0, 1, 2, 3, 4, 5],)
558- 
559- #          assert test_results[1].id.function_getting_tested == "sorter"
560- #          assert test_results[1].id.iteration_id == "4_0"
561- #          assert test_results[1].id.test_class_name is None
562- #          assert test_results[1].id.test_function_name == "test_sort"
563- #          assert (
564- #              test_results[1].id.test_module_path
565- #              == "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp"
566- #          )
567- #          assert test_results[1].runtime > 0
568- #          assert test_results[1].did_pass
569- 
570- #          with test_path_perf.open("w") as f:
571- #              f.write(new_perf_test)
572- 
573- #          test_results_perf, _ = func_optimizer.run_and_parse_tests(
574- #              testing_type=TestingMode.PERFORMANCE,
575- #              test_env=test_env,
576- #              test_files=test_files,
577- #              optimization_iteration=0,
578- #              pytest_min_loops=1,
579- #              pytest_max_loops=1,
580- #              testing_time=0.1,
581- #          )
582- #          assert test_results_perf[0].id.function_getting_tested == "sorter"
583- #          assert test_results_perf[0].id.iteration_id == "1_0"
584- #          assert test_results_perf[0].id.test_class_name is None
585- #          assert test_results_perf[0].id.test_function_name == "test_sort"
586- #          assert (
587- #              test_results_perf[0].id.test_module_path
588- #              == "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp"
589- #          )
590- #          assert test_results_perf[0].runtime > 0
591- #          assert test_results_perf[0].did_pass
592- #          assert test_results_perf[0].return_value is None
593- 
594- #          assert test_results_perf[1].id.function_getting_tested == "sorter"
595- #          assert test_results_perf[1].id.iteration_id == "4_0"
596- #          assert test_results_perf[1].id.test_class_name is None
597- #          assert test_results_perf[1].id.test_function_name == "test_sort"
598- #          assert (
599- #              test_results_perf[1].id.test_module_path
600- #              == "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp"
601- #          )
602- #          assert test_results_perf[1].runtime > 0
603- #          assert test_results_perf[1].did_pass
604- #          out_str = """codeflash stdout: Sorting list
605- #  result: [0, 1, 2, 3, 4, 5]
606- 
607- #  codeflash stdout: Sorting list
608- #  result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]"""
609- #          assert out_str == test_results_perf[1].stdout
610- #          ctx_result = func_optimizer.get_code_optimization_context()
611- #          code_context: CodeOptimizationContext = ctx_result.unwrap()
612- #          original_helper_code: dict[Path, str] = {}
613- #          helper_function_paths = {hf.file_path for hf in code_context.helper_functions}
614- #          for helper_function_path in helper_function_paths:
615- #              with helper_function_path.open(encoding="utf8") as f:
616- #                  helper_code = f.read()
617- #                  original_helper_code[helper_function_path] = helper_code
618- #          computed_fn_opt = True
619- #          line_profiler_output_file = add_decorator_imports(
620- #              func_optimizer.function_to_optimize, code_context)
621- #          line_profile_results, _ = func_optimizer.run_and_parse_tests(
622- #              testing_type=TestingMode.LINE_PROFILE,
623- #              test_env=test_env,
624- #              test_files=test_files,
625- #              optimization_iteration=0,
626- #              pytest_min_loops=1,
627- #              pytest_max_loops=1,
628- #              testing_time=0.1,
629- #              line_profiler_output_file = line_profiler_output_file
630- #          )
631- #          tmp_lpr = list(line_profile_results["timings"].keys())
632- #          assert len(tmp_lpr) == 1 and line_profile_results["timings"][tmp_lpr[0]][0][1]==2
548+         assert  test_results [0 ].id .iteration_id  ==  "1_0" 
549+         assert  test_results [0 ].id .test_class_name  is  None 
550+         assert  test_results [0 ].id .test_function_name  ==  "test_sort" 
551+         assert  (
552+             test_results [0 ].id .test_module_path 
553+             ==  "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp" 
554+         )
555+         assert  test_results [0 ].runtime  >  0 
556+         assert  test_results [0 ].did_pass 
557+         assert  test_results [0 ].return_value  ==  ([0 , 1 , 2 , 3 , 4 , 5 ],)
558+ 
559+         assert  test_results [1 ].id .function_getting_tested  ==  "sorter" 
560+         assert  test_results [1 ].id .iteration_id  ==  "4_0" 
561+         assert  test_results [1 ].id .test_class_name  is  None 
562+         assert  test_results [1 ].id .test_function_name  ==  "test_sort" 
563+         assert  (
564+             test_results [1 ].id .test_module_path 
565+             ==  "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp" 
566+         )
567+         assert  test_results [1 ].runtime  >  0 
568+         assert  test_results [1 ].did_pass 
569+ 
570+         with  test_path_perf .open ("w" ) as  f :
571+             f .write (new_perf_test )
572+ 
573+         test_results_perf , _  =  func_optimizer .run_and_parse_tests (
574+             testing_type = TestingMode .PERFORMANCE ,
575+             test_env = test_env ,
576+             test_files = test_files ,
577+             optimization_iteration = 0 ,
578+             pytest_min_loops = 1 ,
579+             pytest_max_loops = 1 ,
580+             testing_time = 0.1 ,
581+         )
582+         assert  test_results_perf [0 ].id .function_getting_tested  ==  "sorter" 
583+         assert  test_results_perf [0 ].id .iteration_id  ==  "1_0" 
584+         assert  test_results_perf [0 ].id .test_class_name  is  None 
585+         assert  test_results_perf [0 ].id .test_function_name  ==  "test_sort" 
586+         assert  (
587+             test_results_perf [0 ].id .test_module_path 
588+             ==  "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp" 
589+         )
590+         assert  test_results_perf [0 ].runtime  >  0 
591+         assert  test_results_perf [0 ].did_pass 
592+         assert  test_results_perf [0 ].return_value  is  None 
593+ 
594+         assert  test_results_perf [1 ].id .function_getting_tested  ==  "sorter" 
595+         assert  test_results_perf [1 ].id .iteration_id  ==  "4_0" 
596+         assert  test_results_perf [1 ].id .test_class_name  is  None 
597+         assert  test_results_perf [1 ].id .test_function_name  ==  "test_sort" 
598+         assert  (
599+             test_results_perf [1 ].id .test_module_path 
600+             ==  "code_to_optimize.tests.pytest.test_perfinjector_bubble_sort_results_temp" 
601+         )
602+         assert  test_results_perf [1 ].runtime  >  0 
603+         assert  test_results_perf [1 ].did_pass 
604+         out_str  =  """codeflash stdout: Sorting list 
605+ result: [0, 1, 2, 3, 4, 5] 
606+ 
607+ codeflash stdout: Sorting list 
608+ result: [0.0, 1.0, 2.0, 3.0, 4.0, 5.0]""" 
609+         assert  out_str  ==  test_results_perf [1 ].stdout 
610+         ctx_result  =  func_optimizer .get_code_optimization_context ()
611+         code_context : CodeOptimizationContext  =  ctx_result .unwrap ()
612+         original_helper_code : dict [Path , str ] =  {}
613+         helper_function_paths  =  {hf .file_path  for  hf  in  code_context .helper_functions }
614+         for  helper_function_path  in  helper_function_paths :
615+             with  helper_function_path .open (encoding = "utf8" ) as  f :
616+                 helper_code  =  f .read ()
617+                 original_helper_code [helper_function_path ] =  helper_code 
618+         computed_fn_opt  =  True 
619+         line_profiler_output_file  =  add_decorator_imports (
620+             func_optimizer .function_to_optimize , code_context )
621+         line_profile_results , _  =  func_optimizer .run_and_parse_tests (
622+             testing_type = TestingMode .LINE_PROFILE ,
623+             test_env = test_env ,
624+             test_files = test_files ,
625+             optimization_iteration = 0 ,
626+             pytest_min_loops = 1 ,
627+             pytest_max_loops = 1 ,
628+             testing_time = 0.1 ,
629+             line_profiler_output_file  =  line_profiler_output_file 
630+         )
631+         tmp_lpr  =  list (line_profile_results ["timings" ].keys ())
632+         assert  len (tmp_lpr ) ==  1  and  line_profile_results ["timings" ][tmp_lpr [0 ]][0 ][1 ]== 2 
633633    finally :
634634        if  computed_fn_opt :
635635            func_optimizer .write_code_and_helpers (
0 commit comments