-
Notifications
You must be signed in to change notification settings - Fork 5.9k
/
Copy pathtest_patch_whitespace.py
79 lines (67 loc) · 2 KB
/
test_patch_whitespace.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from openhands.resolver.patching.apply import apply_diff
from openhands.resolver.patching.patch import parse_patch
def test_patch_whitespace_mismatch():
"""Test that the patch application succeeds even when whitespace doesn't match."""
# Original content has a line with spaces
original_content = """class Example:
def method(self):
pass
def another(self):
pass"""
# Patch expects an empty line (no spaces)
patch_text = """diff --git a/example.py b/example.py
index 1234567..89abcdef 100644
--- a/example.py
+++ b/example.py
@@ -2,6 +2,10 @@ class Example:
def method(self):
pass
+ new_field: str = "value"
+
def another(self):
pass"""
patch = next(parse_patch(patch_text))
# The patch should still work because we normalize whitespace
new_content = apply_diff(patch, original_content)
assert new_content == [
'class Example:',
' def method(self):',
' pass',
'',
' new_field: str = "value"',
'',
' def another(self):',
' pass',
]
def test_patch_whitespace_match():
"""Test that the patch application succeeds when whitespace matches."""
# Original content has an empty line (no spaces)
original_content = """class Example:
def method(self):
pass
def another(self):
pass"""
# Patch expects an empty line (no spaces)
patch_text = """diff --git a/example.py b/example.py
index 1234567..89abcdef 100644
--- a/example.py
+++ b/example.py
@@ -2,6 +2,10 @@ class Example:
def method(self):
pass
+ new_field: str = "value"
+
def another(self):
pass"""
patch = next(parse_patch(patch_text))
new_content = apply_diff(patch, original_content)
assert new_content == [
'class Example:',
' def method(self):',
' pass',
'',
' new_field: str = "value"',
'',
' def another(self):',
' pass',
]