Skip to content

Commit a2cd6da

Browse files
committed
Merge branch 'list_tests@v1.9' into list_tests@v1.13
Conflicts: tests.py
2 parents b15d8f1 + 73acf7f commit a2cd6da

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
@@ -327,13 +327,18 @@ def test_use_move_instead_of_remove_add(self):
327327
self.assertEqual(res, dst)
328328

329329
def test_use_move_instead_of_add_remove(self):
330-
src = {'foo': [1, 2, 3]}
331-
dst = {'foo': [3, 1, 2]}
332-
patch = list(jsonpatch.make_patch(src, dst))
333-
self.assertEqual(len(patch), 1)
334-
self.assertEqual(patch[0]['op'], 'move')
335-
res = jsonpatch.apply_patch(src, patch)
336-
self.assertEqual(res, dst)
330+
def fn(_src, _dst):
331+
patch = list(jsonpatch.make_patch(_src, _dst))
332+
# Check if there are only 'move' operations
333+
for p in patch:
334+
self.assertEqual(p['op'], 'move')
335+
res = jsonpatch.apply_patch(_src, patch)
336+
self.assertEqual(res, _dst)
337+
338+
fn({'foo': [1, 2, 3]}, {'foo': [3, 1, 2]})
339+
fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]})
340+
fn([1, 2, 3], [3, 1, 2])
341+
fn([1, 2, 3], [3, 2, 1])
337342

338343
def test_escape(self):
339344
src = {"x/y": 1}
@@ -383,6 +388,41 @@ def test_minimal_patch(self):
383388
self.assertEqual(patch.patch, exp)
384389

385390

391+
class ListTests(unittest.TestCase):
392+
393+
def test_fail_prone_list_1(self):
394+
""" Test making and applying a patch of the root is a list """
395+
src = ['a', 'r', 'b']
396+
dst = ['b', 'o']
397+
patch = jsonpatch.make_patch(src, dst)
398+
res = patch.apply(src)
399+
self.assertEqual(res, dst)
400+
401+
def test_fail_prone_list_2(self):
402+
""" Test making and applying a patch of the root is a list """
403+
src = ['a', 'r', 'b', 'x', 'm', 'n']
404+
dst = ['b', 'o', 'm', 'n']
405+
patch = jsonpatch.make_patch(src, dst)
406+
res = patch.apply(src)
407+
self.assertEqual(res, dst)
408+
409+
def test_fail_prone_list_3(self):
410+
""" Test making and applying a patch of the root is a list """
411+
src = ['boo1', 'bar', 'foo1', 'qux']
412+
dst = ['qux', 'bar']
413+
patch = jsonpatch.make_patch(src, dst)
414+
res = patch.apply(src)
415+
self.assertEqual(res, dst)
416+
417+
def test_fail_prone_list_4(self):
418+
""" Test making and applying a patch of the root is a list """
419+
src = ['bar1', 59, 'foo1', 'foo']
420+
dst = ['foo', 'bar', 'foo1']
421+
patch = jsonpatch.make_patch(src, dst)
422+
res = patch.apply(src)
423+
self.assertEqual(res, dst)
424+
425+
386426
class InvalidInputTests(unittest.TestCase):
387427

388428
def test_missing_op(self):
@@ -447,6 +487,7 @@ def get_suite():
447487
suite.addTest(unittest.makeSuite(ApplyPatchTestCase))
448488
suite.addTest(unittest.makeSuite(EqualityTestCase))
449489
suite.addTest(unittest.makeSuite(MakePatchTestCase))
490+
suite.addTest(unittest.makeSuite(ListTests))
450491
suite.addTest(unittest.makeSuite(InvalidInputTests))
451492
suite.addTest(unittest.makeSuite(ConflictTests))
452493
return suite

0 commit comments

Comments
 (0)