Skip to content

Commit 49b6c74

Browse files
committed
Tolerate Hypothesis being missing (no 2.6, 3.2, or 3.3 support).
1 parent 313e1b3 commit 49b6c74

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ python:
1111
- "pypy3"
1212

1313
install:
14-
- travis_retry pip install -r requirements.txt -r requirements-dev.txt
14+
- travis_retry pip install -r requirements.txt
15+
- if [ "$TRAVIS_PYTHON_VERSION" != "2.6" -a "$TRAVIS_PYTHON_VERSION" != "3.2" -a "$TRAVIS_PYTHON_VERSION" != "3.3" ]; then travis_retry pip install hypothesis; fi
1516
- if [ "$TRAVIS_PYTHON_VERSION" == "3.2" ]; then travis_retry pip install 'coverage<4'; fi
1617
- travis_retry pip install coveralls
1718

tests.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
import jsonpointer
1111
import sys
1212
import string
13-
from hypothesis import given, note, strategies as st
13+
try:
14+
import hypothesis
15+
from hypothesis import strategies as st
16+
except ImportError:
17+
hypothesis = None
1418

1519

1620
class ApplyPatchTestCase(unittest.TestCase):
@@ -520,24 +524,24 @@ def test_replace_missing(self):
520524
self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj)
521525

522526

523-
json_st = st.recursive(
524-
st.one_of([
525-
st.none(),
526-
st.booleans(),
527-
st.floats(allow_nan=False),
528-
st.text(string.printable)]),
529-
lambda children:
530-
st.lists(children)
531-
| st.dictionaries(st.text(string.printable), children))
527+
if hypothesis is not None:
528+
json_st = st.recursive(
529+
st.one_of([
530+
st.none(),
531+
st.booleans(),
532+
st.floats(allow_nan=False),
533+
st.text(string.printable)]),
534+
lambda children:
535+
st.lists(children)
536+
| st.dictionaries(st.text(string.printable), children))
532537

533-
534-
class RoundtripTests(unittest.TestCase):
535-
@given(json_st, json_st)
536-
def test_roundtrip(self, src, dst):
537-
patch = jsonpatch.JsonPatch.from_diff(src, dst, False)
538-
note('Patch: %s' % (patch,))
539-
res = patch.apply(src)
540-
self.assertEqual(res, dst)
538+
class RoundtripTests(unittest.TestCase):
539+
@hypothesis.given(json_st, json_st)
540+
def test_roundtrip(self, src, dst):
541+
patch = jsonpatch.JsonPatch.from_diff(src, dst, False)
542+
hypothesis.note('Patch: %s' % (patch,))
543+
res = patch.apply(src)
544+
self.assertEqual(res, dst)
541545

542546

543547
if __name__ == '__main__':
@@ -553,7 +557,8 @@ def get_suite():
553557
suite.addTest(unittest.makeSuite(InvalidInputTests))
554558
suite.addTest(unittest.makeSuite(ConflictTests))
555559
suite.addTest(unittest.makeSuite(OptimizationTests))
556-
suite.addTest(unittest.makeSuite(RoundtripTests))
560+
if hypothesis is not None:
561+
suite.addTest(unittest.makeSuite(RoundtripTests))
557562
return suite
558563

559564

0 commit comments

Comments
 (0)