Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
RajWorking committed Nov 16, 2024
1 parent 57fba09 commit 182079c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
14 changes: 8 additions & 6 deletions openhands_aci/editor/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult:

self._validate_range(lines_range, num_lines)

start_line, end_line = lines_range # inclusive
start_line, end_line = lines_range # inclusive

new_file_text_lines = (
file_text_lines[:start_line]
+ file_text_lines[end_line + 1:]
file_text_lines[:start_line] + file_text_lines[end_line + 1:]
)
snippet_lines = (
file_text_lines[max(0, start_line - SNIPPET_CONTEXT_WINDOW) : start_line]
Expand All @@ -312,16 +311,19 @@ def delete(self, path: Path, lines_range: list[int]) -> CLIResult:
success_message += 'Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary.'
return CLIResult(output=success_message)

def move_code_block(self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int) -> CLIResult:
def move_code_block(
self, from_file: Path, from_range: list[int], dst_file: Path, insert_line: int
) -> CLIResult:
"""
Move a block of code from one file to another.
"""
file_content = self.read_file(from_file)
file_content_lines = file_content.split('\n')
start_line, end_line = from_range
code_block = '\n'.join(
file_content_lines[start_line:] if end_line == -1 else
file_content_lines[start_line: end_line + 1]
file_content_lines[start_line:]
if end_line == -1
else file_content_lines[start_line: end_line + 1]
)
delete_result = self.delete(from_file, from_range)
insert_result = self.insert(dst_file, insert_line, code_block, True)
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/test_file_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,17 @@ def test_insert_with_linting(editor):
Review the changes and make sure they are as expected (correct indentation, no duplicate lines, etc). Edit the file again if necessary."""
)


def test_move_code_block(editor):
editor, test_file = editor
test_file.write_text('This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz')
test_file.write_text(
'This is a test file.\nThis file is for testing purposes.\nfoo\nbar\nbaz'
)

second_test_file = test_file.parent / 'second_test.txt'
second_test_file.write_text('This is also a test file.\nSome text should be added above this.')
second_test_file.write_text(
'This is also a test file.\nSome text should be added above this.'
)

result = editor(
command='move_code_block',
Expand Down

0 comments on commit 182079c

Please sign in to comment.