|
1 | 1 | # -*- coding: utf-8 -*-
|
2 | 2 |
|
3 |
| -import whatthepatch as wtp |
4 |
| -from whatthepatch import exceptions |
| 3 | +import unittest |
| 4 | +import difflib |
5 | 5 |
|
| 6 | +from hypothesis import given, assume |
| 7 | +from hypothesis import strategies as st |
6 | 8 | from nose.tools import assert_raises
|
7 |
| -import unittest |
| 9 | + |
| 10 | +from whatthepatch import exceptions |
| 11 | +import whatthepatch as wtp |
8 | 12 |
|
9 | 13 |
|
10 | 14 | def _apply(src, diff_text, reverse=False, use_patch=False):
|
11 |
| - diff = next(wtp.parse_patch(diff_text)) |
12 |
| - return wtp.apply.apply_diff(diff, src, reverse, use_patch) |
| 15 | + diff = list(wtp.parse_patch(diff_text)) |
| 16 | + assert len(diff) == 1 |
| 17 | + return wtp.apply.apply_diff(diff[0], src, reverse, use_patch) |
13 | 18 |
|
14 | 19 |
|
15 | 20 | def _apply_r(src, diff_text, reverse=True, use_patch=False):
|
@@ -147,5 +152,28 @@ def test_diff_ed(self):
|
147 | 152 | self.assertEqual(new_text, (self.tzu, None))
|
148 | 153 |
|
149 | 154 |
|
| 155 | + @given( |
| 156 | + st.text(), st.text(), st.text(), st.text(), st.datetimes(), |
| 157 | + st.datetimes(), st.integers(), |
| 158 | + ) |
| 159 | + def test_apply_reverse(self, a, b, fromfile, tofile, fromdate, todate, n): |
| 160 | + diff = list(difflib.unified_diff( |
| 161 | + a.split('\n'), |
| 162 | + b.split('\n'), |
| 163 | + fromfile=fromfile, |
| 164 | + tofile=tofile, |
| 165 | + fromfiledate=fromdate.isoformat(), |
| 166 | + tofiledate=todate.isoformat(), |
| 167 | + n=n, |
| 168 | + lineterm='', |
| 169 | + )) |
| 170 | + assume(diff) |
| 171 | + a_str = a |
| 172 | + b_str = b |
| 173 | + |
| 174 | + self.assertEqual(_apply(a_str.split('\n'), diff[:]), b_str.split('\n')) |
| 175 | + self.assertEqual(_apply_r(b_str.split('\n'), diff[:]), a_str.split('\n')) |
| 176 | + |
| 177 | + |
150 | 178 | if __name__ == '__main__':
|
151 | 179 | unittest.main()
|
0 commit comments