summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Kögl <stefan@skoegl.net>2017-09-03 11:51:41 +0200
committerStefan Kögl <stefan@skoegl.net>2017-09-03 11:51:41 +0200
commitf0a4f51e32c77f9c774c26ef339dbd95cfa8ffa7 (patch)
tree3a56a6185c6f9dced64b1b8f993850a0b35dfe34
parent4d9adf195be16d8ae99468359e0ac876479482c7 (diff)
parentfbc904f93e8db3d6f082d7fdc638379ca8fec0ec (diff)
downloadpython-json-patch-f0a4f51e32c77f9c774c26ef339dbd95cfa8ffa7.tar.gz
Merge branch 'list_tests'
-rwxr-xr-xtests.py59
1 files changed, 52 insertions, 7 deletions
diff --git a/tests.py b/tests.py
index 51d9517..6a8234f 100755
--- a/tests.py
+++ b/tests.py
@@ -407,13 +407,22 @@ class OptimizationTests(unittest.TestCase):
self.assertEqual(res, dst)
def test_use_move_instead_of_add_remove(self):
- src = {'foo': [1, 2, 3]}
- dst = {'foo': [3, 1, 2]}
- patch = list(jsonpatch.make_patch(src, dst))
- self.assertEqual(len(patch), 1)
- self.assertEqual(patch[0]['op'], 'move')
- res = jsonpatch.apply_patch(src, patch)
- self.assertEqual(res, dst)
+ def fn(_src, _dst):
+ patch = list(jsonpatch.make_patch(_src, _dst))
+ # Check if there are only 'move' operations
+ for p in patch:
+ self.assertEqual(p['op'], 'move')
+ res = jsonpatch.apply_patch(_src, patch)
+ self.assertEqual(res, _dst)
+
+ fn({'foo': [1, 2, 3]}, {'foo': [3, 1, 2]})
+ fn([1, 2, 3], [3, 1, 2])
+
+ # Optimizations for the following tests are currently not performed.
+ # The tests are disabled, as the missing optimizations do not
+ # invalidate the results
+ #fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]})
+ #fn([1, 2, 3], [3, 2, 1])
def test_success_if_replace_inside_dict(self):
src = [{'a': 1, 'foo': {'b': 2, 'd': 5}}]
@@ -464,6 +473,41 @@ class OptimizationTests(unittest.TestCase):
self.assertEqual(patch.patch, exp)
+class ListTests(unittest.TestCase):
+
+ def test_fail_prone_list_1(self):
+ """ Test making and applying a patch of the root is a list """
+ src = ['a', 'r', 'b']
+ dst = ['b', 'o']
+ patch = jsonpatch.make_patch(src, dst)
+ res = patch.apply(src)
+ self.assertEqual(res, dst)
+
+ def test_fail_prone_list_2(self):
+ """ Test making and applying a patch of the root is a list """
+ src = ['a', 'r', 'b', 'x', 'm', 'n']
+ dst = ['b', 'o', 'm', 'n']
+ patch = jsonpatch.make_patch(src, dst)
+ res = patch.apply(src)
+ self.assertEqual(res, dst)
+
+ def test_fail_prone_list_3(self):
+ """ Test making and applying a patch of the root is a list """
+ src = ['boo1', 'bar', 'foo1', 'qux']
+ dst = ['qux', 'bar']
+ patch = jsonpatch.make_patch(src, dst)
+ res = patch.apply(src)
+ self.assertEqual(res, dst)
+
+ def test_fail_prone_list_4(self):
+ """ Test making and applying a patch of the root is a list """
+ src = ['bar1', 59, 'foo1', 'foo']
+ dst = ['foo', 'bar', 'foo1']
+ patch = jsonpatch.make_patch(src, dst)
+ res = patch.apply(src)
+ self.assertEqual(res, dst)
+
+
class InvalidInputTests(unittest.TestCase):
def test_missing_op(self):
@@ -528,6 +572,7 @@ if __name__ == '__main__':
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
suite.addTest(unittest.makeSuite(EqualityTestCase))
suite.addTest(unittest.makeSuite(MakePatchTestCase))
+ suite.addTest(unittest.makeSuite(ListTests))
suite.addTest(unittest.makeSuite(InvalidInputTests))
suite.addTest(unittest.makeSuite(ConflictTests))
suite.addTest(unittest.makeSuite(OptimizationTests))