diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | requirements-dev.txt | 1 | ||||
-rwxr-xr-x | tests.py | 23 |
3 files changed, 25 insertions, 0 deletions
@@ -4,3 +4,4 @@ build dist *.egg-info/ doc/_build +.hypothesis/ diff --git a/requirements-dev.txt b/requirements-dev.txt index 21daf9a..744c41c 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,2 +1,3 @@ wheel pypandoc +hypothesis >= 3 @@ -9,6 +9,8 @@ import unittest import jsonpatch import jsonpointer import sys +import string +from hypothesis import given, note, strategies as st class ApplyPatchTestCase(unittest.TestCase): @@ -518,6 +520,26 @@ class ConflictTests(unittest.TestCase): self.assertRaises(jsonpatch.JsonPatchConflict, jsonpatch.apply_patch, src, patch_obj) +json_st = st.recursive( + st.one_of([ + st.none(), + st.booleans(), + st.floats(), + st.text(string.printable)]), + lambda children: + st.lists(children) + | st.dictionaries(st.text(string.printable), children)) + + +class RoundtripTests(unittest.TestCase): + @given(json_st, json_st) + def test_roundtrip(self, src, dst): + patch = jsonpatch.JsonPatch.from_diff(src, dst, False) + note('Patch: %s' % (patch,)) + res = patch.apply(src) + self.assertEqual(res, dst) + + if __name__ == '__main__': modules = ['jsonpatch'] @@ -531,6 +553,7 @@ if __name__ == '__main__': suite.addTest(unittest.makeSuite(InvalidInputTests)) suite.addTest(unittest.makeSuite(ConflictTests)) suite.addTest(unittest.makeSuite(OptimizationTests)) + suite.addTest(unittest.makeSuite(RoundtripTests)) return suite |