diff options
author | Tristan Seligmann <mithrandi@mithrandi.net> | 2017-07-06 15:43:10 +0200 |
---|---|---|
committer | Tristan Seligmann <mithrandi@mithrandi.net> | 2017-07-06 15:43:10 +0200 |
commit | 975893443cc7e1c258c82e1272fbc3fd7268d1df (patch) | |
tree | 64c6e5fe396b8cc5f8fcdc891f1a2876304beec6 | |
parent | 18887df8af5f761aa83c76a7cd3777210b2527ad (diff) | |
download | python-json-patch-975893443cc7e1c258c82e1272fbc3fd7268d1df.tar.gz |
Add property based test.
-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 |