@@ -407,13 +407,22 @@ def test_use_move_instead_of_remove_add(self):
407
407
self .assertEqual (res , dst )
408
408
409
409
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 ([1 , 2 , 3 ], [3 , 1 , 2 ])
420
+
421
+ # Optimizations for the following tests are currently not performed.
422
+ # The tests are disabled, as the missing optimizations do not
423
+ # invalidate the results
424
+ #fn({'foo': [1, 2, 3]}, {'foo': [3, 2, 1]})
425
+ #fn([1, 2, 3], [3, 2, 1])
417
426
418
427
def test_success_if_replace_inside_dict (self ):
419
428
src = [{'a' : 1 , 'foo' : {'b' : 2 , 'd' : 5 }}]
@@ -464,6 +473,41 @@ def test_minimal_patch(self):
464
473
self .assertEqual (patch .patch , exp )
465
474
466
475
476
+ class ListTests (unittest .TestCase ):
477
+
478
+ def test_fail_prone_list_1 (self ):
479
+ """ Test making and applying a patch of the root is a list """
480
+ src = ['a' , 'r' , 'b' ]
481
+ dst = ['b' , 'o' ]
482
+ patch = jsonpatch .make_patch (src , dst )
483
+ res = patch .apply (src )
484
+ self .assertEqual (res , dst )
485
+
486
+ def test_fail_prone_list_2 (self ):
487
+ """ Test making and applying a patch of the root is a list """
488
+ src = ['a' , 'r' , 'b' , 'x' , 'm' , 'n' ]
489
+ dst = ['b' , 'o' , 'm' , 'n' ]
490
+ patch = jsonpatch .make_patch (src , dst )
491
+ res = patch .apply (src )
492
+ self .assertEqual (res , dst )
493
+
494
+ def test_fail_prone_list_3 (self ):
495
+ """ Test making and applying a patch of the root is a list """
496
+ src = ['boo1' , 'bar' , 'foo1' , 'qux' ]
497
+ dst = ['qux' , 'bar' ]
498
+ patch = jsonpatch .make_patch (src , dst )
499
+ res = patch .apply (src )
500
+ self .assertEqual (res , dst )
501
+
502
+ def test_fail_prone_list_4 (self ):
503
+ """ Test making and applying a patch of the root is a list """
504
+ src = ['bar1' , 59 , 'foo1' , 'foo' ]
505
+ dst = ['foo' , 'bar' , 'foo1' ]
506
+ patch = jsonpatch .make_patch (src , dst )
507
+ res = patch .apply (src )
508
+ self .assertEqual (res , dst )
509
+
510
+
467
511
class InvalidInputTests (unittest .TestCase ):
468
512
469
513
def test_missing_op (self ):
@@ -528,6 +572,7 @@ def get_suite():
528
572
suite .addTest (unittest .makeSuite (ApplyPatchTestCase ))
529
573
suite .addTest (unittest .makeSuite (EqualityTestCase ))
530
574
suite .addTest (unittest .makeSuite (MakePatchTestCase ))
575
+ suite .addTest (unittest .makeSuite (ListTests ))
531
576
suite .addTest (unittest .makeSuite (InvalidInputTests ))
532
577
suite .addTest (unittest .makeSuite (ConflictTests ))
533
578
suite .addTest (unittest .makeSuite (OptimizationTests ))
0 commit comments