Skip to content

Commit 4d232c9

Browse files
author
Thomas Grainger
committed
Rase apply exceptions with hunk context info
1 parent 6b342d5 commit 4d232c9

File tree

8 files changed

+232
-93
lines changed

8 files changed

+232
-93
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pip-log.txt
3131
.coverage
3232
.tox
3333
nosetests.xml
34+
.noseids
3435

3536
# Translations
3637
*.mo
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- lao 2013-01-05 16:56:19.000000000 -0600
2+
+++ tzu 2013-01-05 16:56:35.000000000 -0600
3+
@@ -1,7 +1,6 @@
4+
-The Way that can be told of is not the eternal Way;
5+
-The name that can be named is not the eternal name.
6+
The Nameless is the origin of Heaven and Earth;
7+
-The Named is the mother of all tings.
8+
+The named is the mother of all things.
9+
+
10+
Therefore let there always be non-being,
11+
so we may see their subtlety,
12+
And let there always be being,
13+
@@ -9,3 +8,6 @@
14+
The two are the same,
15+
But after they are produced,
16+
they have different names.
17+
+They both may be called deep and profound.
18+
+Deeper and more profound,
19+
+The door of all subtleties!
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--- lao 2013-01-05 16:56:19.000000000 -0600
2+
+++ tzu 2013-01-05 16:56:35.000000000 -0600
3+
@@ -1,7 +1,6 @@
4+
-The Way that can be told of is not the eternal Way;
5+
-The name that can be named is not the eternal name.
6+
The Nameless is the origin of Heaven and Earth;
7+
-The Named is the mother of all things.
8+
+The named is the mother of all things.
9+
+
10+
Therefore let there always be non-being,
11+
so we may see their subtlety,
12+
And let there always be being,
13+
@@ -9,3 +8,6 @@
14+
The two are te same,
15+
But after they are produced,
16+
they have different names.
17+
+They both may be called deep and profound.
18+
+Deeper and more profound,
19+
+The door of all subtleties!

tests/test_apply.py

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import whatthepatch as wtp
44
from whatthepatch import exceptions
55

6-
6+
from nose.tools import assert_raises
77
import unittest
88

99

@@ -51,6 +51,70 @@ def test_diff_unified(self):
5151

5252
self.assertEqual(new_text, self.tzu)
5353

54+
def test_diff_unified_bad(self):
55+
with open('tests/casefiles/diff-unified-bad.diff') as f:
56+
diff_text = f.read()
57+
58+
diff = next(wtp.parse_patch(diff_text))
59+
60+
with assert_raises(exceptions.ApplyException) as ec:
61+
wtp.apply.apply_diff(diff, self.lao)
62+
63+
e = ec.exception
64+
e_str = str(e)
65+
assert 'line 4' in e_str
66+
assert 'The Named is the mother of all tings.' in e_str
67+
assert 'The Named is the mother of all things.' in e_str
68+
assert e.hunk == 1
69+
70+
def test_diff_unified_bad2(self):
71+
with open('tests/casefiles/diff-unified-bad2.diff') as f:
72+
diff_text = f.read()
73+
74+
diff = next(wtp.parse_patch(diff_text))
75+
76+
with assert_raises(exceptions.ApplyException) as ec:
77+
wtp.apply.apply_diff(diff, self.lao)
78+
79+
e = ec.exception
80+
e_str = str(e)
81+
assert 'line 9' in e_str
82+
assert 'The two are te same,' in e_str
83+
assert 'The two are the same,' in e_str
84+
assert e.hunk == 2
85+
86+
def test_diff_unified_bad_backward(self):
87+
with open('tests/casefiles/diff-unified-bad2.diff') as f:
88+
diff_text = f.read()
89+
90+
diff = next(wtp.parse_patch(diff_text))
91+
92+
with assert_raises(exceptions.ApplyException) as ec:
93+
wtp.apply.apply_diff(diff, self.tzu)
94+
95+
e = ec.exception
96+
e_str = str(e)
97+
assert 'line 1' in e_str
98+
assert 'The Way that can be told of is not the eternal Way;' in e_str
99+
assert 'The Nameless is the origin of Heaven and Earth;' in e_str
100+
assert e.hunk == 1
101+
102+
def test_diff_unified_bad_empty_source(self):
103+
with open('tests/casefiles/diff-unified-bad2.diff') as f:
104+
diff_text = f.read()
105+
106+
diff = next(wtp.parse_patch(diff_text))
107+
108+
with assert_raises(exceptions.ApplyException) as ec:
109+
wtp.apply.apply_diff(diff, '')
110+
111+
e = ec.exception
112+
e_str = str(e)
113+
assert 'line 1' in e_str
114+
assert 'The Way that can be told of is not the eternal Way;' in e_str
115+
assert 'does not exist in source'
116+
assert e.hunk == 1
117+
54118
def test_diff_unified_patchutil(self):
55119
with open('tests/casefiles/diff-unified.diff') as f:
56120
diff_text = f.read()

0 commit comments

Comments
 (0)