|
3 | 3 | import whatthepatch as wtp
|
4 | 4 | from whatthepatch import exceptions
|
5 | 5 |
|
6 |
| - |
| 6 | +from nose.tools import assert_raises |
7 | 7 | import unittest
|
8 | 8 |
|
9 | 9 |
|
@@ -51,6 +51,70 @@ def test_diff_unified(self):
|
51 | 51 |
|
52 | 52 | self.assertEqual(new_text, self.tzu)
|
53 | 53 |
|
| 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 | + |
54 | 118 | def test_diff_unified_patchutil(self):
|
55 | 119 | with open('tests/casefiles/diff-unified.diff') as f:
|
56 | 120 | diff_text = f.read()
|
|
0 commit comments