Skip to content

Commit b4627cc

Browse files
Thomas Graingergraingert
authored andcommitted
add hypothesis
1 parent bdbcce9 commit b4627cc

File tree

3 files changed

+38
-5
lines changed

3 files changed

+38
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pip-log.txt
3232
.tox
3333
nosetests.xml
3434
.noseids
35+
.hypothesis
3536

3637
# Translations
3738
*.mo

tests/test_apply.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# -*- coding: utf-8 -*-
22

3-
import whatthepatch as wtp
4-
from whatthepatch import exceptions
3+
import unittest
4+
import difflib
55

6+
from hypothesis import given, assume
7+
from hypothesis import strategies as st
68
from nose.tools import assert_raises
7-
import unittest
9+
10+
from whatthepatch import exceptions
11+
import whatthepatch as wtp
812

913

1014
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)
1318

1419

1520
def _apply_r(src, diff_text, reverse=True, use_patch=False):
@@ -146,6 +151,31 @@ def test_diff_ed(self):
146151
new_text = _apply(self.lao, diff_text, use_patch=True)
147152
self.assertEqual(new_text, (self.tzu, None))
148153

154+
@given(
155+
st.text(), st.text(), st.text(), st.text(), st.datetimes(),
156+
st.datetimes(), st.integers(),
157+
)
158+
def test_apply_reverse(self, a, b, fromfile, tofile, fromdate, todate, n):
159+
diff = list(difflib.unified_diff(
160+
a.split('\n'),
161+
b.split('\n'),
162+
fromfile=fromfile,
163+
tofile=tofile,
164+
fromfiledate=fromdate.isoformat(),
165+
tofiledate=todate.isoformat(),
166+
n=n,
167+
lineterm='',
168+
))
169+
assume(diff)
170+
a_str = a
171+
b_str = b
172+
173+
self.assertEqual(_apply(a_str.split('\n'), diff[:]), b_str.split('\n'))
174+
self.assertEqual(
175+
_apply_r(b_str.split('\n'), diff[:]),
176+
a_str.split('\n'),
177+
)
178+
149179

150180
if __name__ == '__main__':
151181
unittest.main()

tox.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ envlist = py{27,34,35,36,37}, lint
44
[testenv]
55
commands = nosetests --with-doctest --doctest-extension=rst {posargs}
66
deps =
7+
pytz
78
nose==1.3.7
9+
hypothesis==4.14.0
810

911
[testenv:lint]
1012
deps =

0 commit comments

Comments
 (0)