Skip to content

Commit 717b0db

Browse files
committed
2 parents 4d9adf1 + a2cd6da commit 717b0db

File tree

1 file changed

+48
-7
lines changed

1 file changed

+48
-7
lines changed

tests.py

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,18 @@ def test_use_move_instead_of_remove_add(self):
407407
self.assertEqual(res, dst)
408408

409409
def test_use_move_instead_of_add_remove(self):
410-
src = {'foo': [1, 2, 3]}
411-
dst = {'foo': [3, 1, 2]}
412-
patch = list(jsonpatch.make_patch(src, dst))
413-
self.assertEqual(len(patch), 1)
414-
self.assertEqual(patch[0]['op'], 'move')
415-
res = jsonpatch.apply_patch(src, patch)
416-
self.assertEqual(res, dst)
410+
def fn(_src, _dst):
411+
patch = list(jsonpatch.make_patch(_src, _dst))
412+
# Check if there are only 'move' operations
413+
for p in patch:
414+
self.assertEqual(p['op'], 'move')
415+
res = jsonpatch.apply_patch(_src, patch)
416+
self.assertEqual(res, _dst)
417+
418+
fn({'foo': [1, 2, 3]}, {'foo': [3, 1, 2]})
419+
fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]})
420+
fn([1, 2, 3], [3, 1, 2])
421+
fn([1, 2, 3], [3, 2, 1])
417422

418423
def test_success_if_replace_inside_dict(self):
419424
src = [{'a': 1, 'foo': {'b': 2, 'd': 5}}]
@@ -464,6 +469,41 @@ def test_minimal_patch(self):
464469
self.assertEqual(patch.patch, exp)
465470

466471

472+
class ListTests(unittest.TestCase):
473+
474+
def test_fail_prone_list_1(self):
475+
""" Test making and applying a patch of the root is a list """
476+
src = ['a', 'r', 'b']
477+
dst = ['b', 'o']
478+
patch = jsonpatch.make_patch(src, dst)
479+
res = patch.apply(src)
480+
self.assertEqual(res, dst)
481+
482+
def test_fail_prone_list_2(self):
483+
""" Test making and applying a patch of the root is a list """
484+
src = ['a', 'r', 'b', 'x', 'm', 'n']
485+
dst = ['b', 'o', 'm', 'n']
486+
patch = jsonpatch.make_patch(src, dst)
487+
res = patch.apply(src)
488+
self.assertEqual(res, dst)
489+
490+
def test_fail_prone_list_3(self):
491+
""" Test making and applying a patch of the root is a list """
492+
src = ['boo1', 'bar', 'foo1', 'qux']
493+
dst = ['qux', 'bar']
494+
patch = jsonpatch.make_patch(src, dst)
495+
res = patch.apply(src)
496+
self.assertEqual(res, dst)
497+
498+
def test_fail_prone_list_4(self):
499+
""" Test making and applying a patch of the root is a list """
500+
src = ['bar1', 59, 'foo1', 'foo']
501+
dst = ['foo', 'bar', 'foo1']
502+
patch = jsonpatch.make_patch(src, dst)
503+
res = patch.apply(src)
504+
self.assertEqual(res, dst)
505+
506+
467507
class InvalidInputTests(unittest.TestCase):
468508

469509
def test_missing_op(self):
@@ -528,6 +568,7 @@ def get_suite():
528568
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
529569
suite.addTest(unittest.makeSuite(EqualityTestCase))
530570
suite.addTest(unittest.makeSuite(MakePatchTestCase))
571+
suite.addTest(unittest.makeSuite(ListTests))
531572
suite.addTest(unittest.makeSuite(InvalidInputTests))
532573
suite.addTest(unittest.makeSuite(ConflictTests))
533574
suite.addTest(unittest.makeSuite(OptimizationTests))

0 commit comments

Comments
 (0)