Skip to content

Commit 0046de3

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

File tree

3 files changed

+36
-5
lines changed

3 files changed

+36
-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: 33 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):
@@ -147,5 +152,28 @@ def test_diff_ed(self):
147152
self.assertEqual(new_text, (self.tzu, None))
148153

149154

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+
150178
if __name__ == '__main__':
151179
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)