File size: 2,106 Bytes
246d201 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
from openhands.resolver.patching.apply import apply_diff
from openhands.resolver.patching.patch import diffobj, parse_diff
def test_patch_apply_with_empty_lines():
# The original file has no indentation and uses \n line endings
original_content = '# PR Viewer\n\nThis React application allows you to view open pull requests from GitHub repositories in a GitHub organization. By default, it uses the All-Hands-AI organization.\n\n## Setup'
# The patch has spaces at the start of each line and uses \n line endings
patch = """diff --git a/README.md b/README.md
index b760a53..5071727 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
# PR Viewer
-This React application allows you to view open pull requests from GitHub repositories in a GitHub organization. By default, it uses the All-Hands-AI organization.
+This React application was created by Graham Neubig and OpenHands. It allows you to view open pull requests from GitHub repositories in a GitHub organization. By default, it uses the All-Hands-AI organization."""
print('Original content lines:')
for i, line in enumerate(original_content.splitlines(), 1):
print(f'{i}: {repr(line)}')
print('\nPatch lines:')
for i, line in enumerate(patch.splitlines(), 1):
print(f'{i}: {repr(line)}')
changes = parse_diff(patch)
print('\nParsed changes:')
for change in changes:
print(
f'Change(old={change.old}, new={change.new}, line={repr(change.line)}, hunk={change.hunk})'
)
diff = diffobj(header=None, changes=changes, text=patch)
# Apply the patch
result = apply_diff(diff, original_content)
# The patch should be applied successfully
expected_result = [
'# PR Viewer',
'',
'This React application was created by Graham Neubig and OpenHands. It allows you to view open pull requests from GitHub repositories in a GitHub organization. By default, it uses the All-Hands-AI organization.',
'',
'## Setup',
]
assert result == expected_result
|