Skip to content

Commit 1933fd1

Browse files
author
Thomas Grainger
committed
add hypothesis
1 parent c1c2bc1 commit 1933fd1

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-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: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
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
8+
from hypothesis.extra.datetime import datetimes
69
from nose.tools import assert_raises
7-
import unittest
10+
11+
from whatthepatch import exceptions
12+
import whatthepatch as wtp
813

914

1015
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)
16+
diff = list(wtp.parse_patch(diff_text))
17+
assert len(diff) == 1
18+
return wtp.apply.apply_diff(diff[0], src, reverse, use_patch)
1319

1420

1521
def _apply_r(src, diff_text, reverse=True, use_patch=False):
@@ -147,5 +153,28 @@ def test_diff_ed(self):
147153
self.assertEqual(new_text, (self.tzu, None))
148154

149155

156+
@given(
157+
st.text(), st.text(), st.text(), st.text(), datetimes(), datetimes(),
158+
st.integers(),
159+
)
160+
def test_apply_reverse(self, a, b, fromfile, tofile, fromdate, todate, n):
161+
diff = list(difflib.unified_diff(
162+
a.split('\n'),
163+
b.split('\n'),
164+
fromfile=fromfile,
165+
tofile=tofile,
166+
fromfiledate=fromdate.isoformat(),
167+
tofiledate=todate.isoformat(),
168+
n=n,
169+
lineterm='',
170+
))
171+
assume(diff)
172+
a_str = a
173+
b_str = b
174+
175+
self.assertEqual(_apply(a_str.split('\n'), diff[:]), b_str.split('\n'))
176+
self.assertEqual(_apply_r(b_str.split('\n'), diff[:]), a_str.split('\n'))
177+
178+
150179
if __name__ == '__main__':
151180
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,33,34,35,36}, lint
44
[testenv]
55
commands = nosetests --with-doctest --doctest-extension=rst {posargs}
66
deps =
7+
pytz
78
nose==1.3.7
9+
hypothesis==3.7.0
810

911
[testenv:lint]
1012
deps =

0 commit comments

Comments
 (0)