Skip to content

Commit 82f4138

Browse files
committed
cleaning up
1 parent d24d24c commit 82f4138

File tree

5 files changed

+75
-125
lines changed

5 files changed

+75
-125
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1+
from code_to_optimize.bubble_sort_dep1_helper import dep1_comparer
2+
from code_to_optimize.bubble_sort_dep2_swap import dep2_swap
3+
4+
15
def sorter_deps(arr):
2-
n = len(arr)
3-
for i in range(n):
4-
# We use a flag to check if the array is already sorted
5-
swapped = False
6-
# Reduce the range of j, since the last i elements are already sorted
7-
for j in range(n - 1 - i):
8-
if arr[j] > arr[j + 1]:
9-
# Swap without a helper function
10-
arr[j], arr[j + 1] = arr[j + 1], arr[j]
11-
swapped = True
12-
# If no elements were swapped in the inner loop, break
13-
if not swapped:
14-
break
6+
for i in range(len(arr)):
7+
for j in range(len(arr) - 1):
8+
if dep1_comparer(arr, j):
9+
dep2_swap(arr, j)
1510
return arr
11+
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
from code_to_optimize.bubble_sort_in_nested_class import WrapperClass
2-
from line_profiler import profile as codeflash_line_profile
32

43

5-
@codeflash_line_profile
64
def sort_classmethod(x):
75
y = WrapperClass.BubbleSortClass()
86
return y.sorter(x)

code_to_optimize/tests/pytest/test_bubble_sort_deps.py

Lines changed: 0 additions & 15 deletions
This file was deleted.

codeflash/verification/parse_line_profile_test_output.py

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,4 @@
1-
"""
2-
This software is OSI Certified Open Source Software.
3-
OSI Certified is a certification mark of the Open Source Initiative.
4-
5-
Copyright (c) 2008, Enthought, Inc.
6-
All rights reserved.
7-
8-
Redistribution and use in source and binary forms, with or without
9-
modification, are permitted provided that the following conditions are met:
10-
11-
* Redistributions of source code must retain the above copyright notice, this
12-
list of conditions and the following disclaimer.
13-
* Redistributions in binary form must reproduce the above copyright notice,
14-
this list of conditions and the following disclaimer in the documentation
15-
and/or other materials provided with the distribution.
16-
* Neither the name of Enthought, Inc. nor the names of its contributors may
17-
be used to endorse or promote products derived from this software without
18-
specific prior written permission.
19-
20-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
24-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
27-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30-
"""
1+
"""Adapted from line_profiler (https://github.com/pyutils/line_profiler) written by Enthought, Inc. (BSD License)"""
312
import linecache
323
import inspect
334
from codeflash.code_utils.tabulate import tabulate

tests/test_test_runner.py

Lines changed: 65 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)