summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Seligmann <mithrandi@mithrandi.net>2017-07-06 15:43:10 +0200
committerTristan Seligmann <mithrandi@mithrandi.net>2017-07-06 15:43:10 +0200
commit975893443cc7e1c258c82e1272fbc3fd7268d1df (patch)
tree64c6e5fe396b8cc5f8fcdc891f1a2876304beec6
parent18887df8af5f761aa83c76a7cd3777210b2527ad (diff)
downloadpython-json-patch-975893443cc7e1c258c82e1272fbc3fd7268d1df.tar.gz
Add property based test.
-rw-r--r--.gitignore1
-rw-r--r--requirements-dev.txt1
-rwxr-xr-xtests.py23
3 files changed, 25 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 179770e..56a7db7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -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
diff --git a/tests.py b/tests.py
index 51d9517..60e3352 100755
--- a/tests.py
+++ b/tests.py
@@ -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