-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
test_unpatch.py
62 lines (48 loc) · 1.26 KB
/
test_unpatch.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
import pytest
import patchy
import patchy.api
def test_unpatch():
def sample():
return 9001
patchy.unpatch(
sample,
"""\
@@ -1,2 +1,2 @@
def sample():
- return 1
+ return 9001
""",
)
assert sample() == 1
def test_unpatch_invalid_unreversed():
"""
We need to balk on patches that fail on application
"""
def sample():
return 1
# This patch would make sense forwards but doesn't backwards
bad_patch = """\
@@ -1,2 +1,2 @@
def sample():
- return 1
+ return 2"""
with pytest.raises(ValueError) as excinfo:
patchy.unpatch(sample, bad_patch)
assert "Unreversed patch detected!" in str(excinfo.value)
assert sample() == 1
def test_unpatch_invalid_hunk():
"""
We need to balk on patches that fail on application
"""
def sample():
return 1
# This patch would make sense forwards but doesn't backwards
bad_patch = """\
@@ -1,2 +1,2 @@
def sample():
- return 3
+ return 2"""
with pytest.raises(ValueError) as excinfo:
patchy.unpatch(sample, bad_patch)
assert "Hunk #1 FAILED" in str(excinfo.value)
assert sample() == 1