Skip to content

Commit b6e3c0d

Browse files
fix unit tests
1 parent b3bd888 commit b6e3c0d

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

code_to_optimize/bubble_sort.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
def sorter(arr):
22
print("codeflash stdout: Sorting list")
3-
arr.sort()
3+
for i in range(len(arr)):
4+
for j in range(len(arr) - 1):
5+
if arr[j] > arr[j + 1]:
6+
temp = arr[j]
7+
arr[j] = arr[j + 1]
8+
arr[j + 1] = temp
49
print(f"result: {arr}")
510
return arr
11+

codeflash/models/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def get_code_block_splitter(file_path: Path) -> str:
165165
return f"{LINE_SPLITTER_MARKER_PREFIX}{file_path}"
166166

167167

168+
splitter_pattern = re.compile(f"^{LINE_SPLITTER_MARKER_PREFIX}([^\n]+)\n", re.MULTILINE | re.DOTALL)
169+
170+
168171
class CodeStringsMarkdown(BaseModel):
169172
code_strings: list[CodeString] = []
170173
_cache: dict = PrivateAttr(default_factory=dict)
@@ -198,9 +201,7 @@ def file_to_path(self) -> dict[str, str]:
198201

199202
@staticmethod
200203
def parse_flattened_code(flat_code: str) -> CodeStringsMarkdown:
201-
pattern = rf"^{LINE_SPLITTER_MARKER_PREFIX}([^\n]+)\n"
202-
matches = list(re.finditer(pattern, flat_code))
203-
204+
matches = list(splitter_pattern.finditer(flat_code))
204205
results = CodeStringsMarkdown()
205206
for i, match in enumerate(matches):
206207
start = match.end()

codeflash/optimization/function_optimizer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ def replace_function_and_helpers_with_optimized_code(
735735
if scoped_optimized_code is None:
736736
logger.warning(
737737
f"Optimized code not found for {relative_module_path} In the context\n-------\n{optimized_code}\n-------\n"
738-
"Existing files in the context are: {list(file_to_code_context.keys())}, re-check your 'split markers'"
738+
"re-check your 'split markers'"
739739
f"existing files are {file_to_code_context.keys()}"
740740
)
741741
scoped_optimized_code = ""

0 commit comments

Comments
 (0)