@@ -108,69 +108,69 @@ def sorter(arr):
108108 arr .sort ()
109109 return arr
110110
111- def test_pytest_line_profile_runner ():
112- def get_fto_cc (file_path ):
113- function_to_optimize = FunctionToOptimize (
114- function_name = "sort_classmethod" , file_path = file_path , parents = [], starting_line = None , ending_line = None
115- )
116- original_helper_code : dict [Path , str ] = {}
117- test_config = TestConfig (
118- tests_root = file_path .parent / "tests" ,
119- tests_project_rootdir = file_path .parent .resolve (),
120- project_root_path = file_path .parent .parent .resolve (),
121- test_framework = "pytest" ,
122- pytest_cmd = "pytest" ,
123- )
124- func_optimizer = FunctionOptimizer (function_to_optimize = function_to_optimize , test_cfg = test_config )
125- ctx_result = func_optimizer .get_code_optimization_context ()
126- if not is_successful (ctx_result ):
127- pytest .fail ()
128- code_context = ctx_result .unwrap ()
129- helper_function_paths = {hf .file_path for hf in code_context .helper_functions }
130- for helper_function_path in helper_function_paths :
131- with helper_function_path .open (encoding = "utf8" ) as f :
132- helper_code = f .read ()
133- original_helper_code [helper_function_path ] = helper_code
134- return func_optimizer , code_context , original_helper_code
135- file_path = (Path (__file__ ) / ".." / ".." / "code_to_optimize" / "bubble_sort_classmethod.py" ).resolve ()
136- func_optimizer , code_context , original_helper_code = get_fto_cc (file_path )
137- #check if decorators are added properly or not
138- file_path_to_helper_classes = defaultdict (set )
139- for function_source in code_context .helper_functions :
140- if (
141- function_source .qualified_name != func_optimizer .function_to_optimize .qualified_name
142- and "." in function_source .qualified_name
143- ):
144- file_path_to_helper_classes [function_source .file_path ].add (function_source .qualified_name .split ("." )[0 ])
145- try :
146- line_profiler_output_file = add_decorator_imports (func_optimizer .function_to_optimize , code_context )
147- except Exception as e :
148- print (e )
149- finally :
150- func_optimizer .write_code_and_helpers (func_optimizer .function_to_optimize_source_code , original_helper_code , func_optimizer .function_to_optimize .file_path )
151- #now check if lp runs properly or not
152- # test_env = os.environ.copy()
153- # test_env["CODEFLASH_TEST_ITERATION"] = "0"
154- # test_env["CODEFLASH_TRACER_DISABLE"] = "1"
155- # if "PYTHONPATH" not in test_env:
156- # test_env["PYTHONPATH"] = str(config.project_root_path)
157- # else:
158- # test_env["PYTHONPATH"] += os.pathsep + str(config.project_root_path)
159- #
160- # with tempfile.NamedTemporaryFile(prefix="test_xx", suffix=".py", dir=cur_dir_path) as fp:
161- # test_files = TestFiles(
162- # test_files=[TestFile(instrumented_behavior_file_path=Path(fp.name), test_type=TestType.EXISTING_UNIT_TEST)]
163- # )
164- # fp.write(code.encode("utf-8"))
165- # fp.flush()
166- # result_file, process = run_line_profile_tests(
167- # test_files,
168- # cwd=cur_dir_path,
169- # test_env=test_env,
170- # test_framework="pytest",
171- # line_profiler_output_file=line_profiler_output_file,
172- # pytest_cmd="pytest",
173- # )
174- # print(process.stdout)
175- # result_file.unlink(missing_ok=True)
111+ # def test_pytest_line_profile_runner():
112+ # def get_fto_cc(file_path):
113+ # function_to_optimize = FunctionToOptimize(
114+ # function_name="sort_classmethod", file_path=file_path, parents=[], starting_line=None, ending_line=None
115+ # )
116+ # original_helper_code: dict[Path, str] = {}
117+ # test_config = TestConfig(
118+ # tests_root=file_path.parent / "tests",
119+ # tests_project_rootdir=file_path.parent.resolve(),
120+ # project_root_path=file_path.parent.parent.resolve(),
121+ # test_framework="pytest",
122+ # pytest_cmd="pytest",
123+ # )
124+ # func_optimizer = FunctionOptimizer(function_to_optimize=function_to_optimize, test_cfg=test_config)
125+ # ctx_result = func_optimizer.get_code_optimization_context()
126+ # if not is_successful(ctx_result):
127+ # pytest.fail()
128+ # code_context = ctx_result.unwrap()
129+ # helper_function_paths = {hf.file_path for hf in code_context.helper_functions}
130+ # for helper_function_path in helper_function_paths:
131+ # with helper_function_path.open(encoding="utf8") as f:
132+ # helper_code = f.read()
133+ # original_helper_code[helper_function_path] = helper_code
134+ # return func_optimizer, code_context, original_helper_code
135+ # file_path = (Path(__file__) / ".." / ".." / "code_to_optimize" / "bubble_sort_classmethod.py").resolve()
136+ # func_optimizer, code_context, original_helper_code = get_fto_cc(file_path)
137+ # #check if decorators are added properly or not
138+ # file_path_to_helper_classes = defaultdict(set)
139+ # for function_source in code_context.helper_functions:
140+ # if (
141+ # function_source.qualified_name != func_optimizer.function_to_optimize.qualified_name
142+ # and "." in function_source.qualified_name
143+ # ):
144+ # file_path_to_helper_classes[function_source.file_path].add(function_source.qualified_name.split(".")[0])
145+ # try:
146+ # line_profiler_output_file = add_decorator_imports(func_optimizer.function_to_optimize, code_context)
147+ # except Exception as e:
148+ # print(e)
149+ # finally:
150+ # func_optimizer.write_code_and_helpers(func_optimizer.function_to_optimize_source_code, original_helper_code, func_optimizer.function_to_optimize.file_path)
151+ # #now check if lp runs properly or not
152+ # # test_env = os.environ.copy()
153+ # # test_env["CODEFLASH_TEST_ITERATION"] = "0"
154+ # # test_env["CODEFLASH_TRACER_DISABLE"] = "1"
155+ # # if "PYTHONPATH" not in test_env:
156+ # # test_env["PYTHONPATH"] = str(config.project_root_path)
157+ # # else:
158+ # # test_env["PYTHONPATH"] += os.pathsep + str(config.project_root_path)
159+ # #
160+ # # with tempfile.NamedTemporaryFile(prefix="test_xx", suffix=".py", dir=cur_dir_path) as fp:
161+ # # test_files = TestFiles(
162+ # # test_files=[TestFile(instrumented_behavior_file_path=Path(fp.name), test_type=TestType.EXISTING_UNIT_TEST)]
163+ # # )
164+ # # fp.write(code.encode("utf-8"))
165+ # # fp.flush()
166+ # # result_file, process = run_line_profile_tests(
167+ # # test_files,
168+ # # cwd=cur_dir_path,
169+ # # test_env=test_env,
170+ # # test_framework="pytest",
171+ # # line_profiler_output_file=line_profiler_output_file,
172+ # # pytest_cmd="pytest",
173+ # # )
174+ # # print(process.stdout)
175+ # # result_file.unlink(missing_ok=True)
176176
0 commit comments