@@ -671,39 +671,45 @@ def test_create_with_pointer(self):
671
671
self .assertEqual (result , expected )
672
672
673
673
674
- class CustomJsonPointerTests (unittest .TestCase ):
674
+ class CustomJsonPointer (jsonpointer .JsonPointer ):
675
+ pass
676
+
677
+
678
+ class PrefixJsonPointer (jsonpointer .JsonPointer ):
679
+ def __init__ (self , pointer ):
680
+ super (PrefixJsonPointer , self ).__init__ ('/foo/bar' + pointer )
675
681
676
- class CustomJsonPointer ( jsonpointer . JsonPointer ):
677
- pass
682
+
683
+ class CustomJsonPointerTests ( unittest . TestCase ):
678
684
679
685
def test_json_patch_from_string (self ):
680
686
patch = '[{"op": "add", "path": "/baz", "value": "qux"}]'
681
687
res = jsonpatch .JsonPatch .from_string (
682
- patch , pointer_cls = self . CustomJsonPointer ,
688
+ patch , pointer_cls = CustomJsonPointer ,
683
689
)
684
- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
690
+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
685
691
686
692
def test_json_patch_from_object (self ):
687
693
patch = [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
688
694
res = jsonpatch .JsonPatch (
689
- patch , pointer_cls = self . CustomJsonPointer ,
695
+ patch , pointer_cls = CustomJsonPointer ,
690
696
)
691
- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
697
+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
692
698
693
699
def test_json_patch_from_diff (self ):
694
700
old = {'foo' : 'bar' }
695
701
new = {'foo' : 'baz' }
696
702
res = jsonpatch .JsonPatch .from_diff (
697
- old , new , pointer_cls = self . CustomJsonPointer ,
703
+ old , new , pointer_cls = CustomJsonPointer ,
698
704
)
699
- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
705
+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
700
706
701
707
def test_apply_patch_from_string (self ):
702
708
obj = {'foo' : 'bar' }
703
709
patch = '[{"op": "add", "path": "/baz", "value": "qux"}]'
704
710
res = jsonpatch .apply_patch (
705
711
obj , patch ,
706
- pointer_cls = self . CustomJsonPointer ,
712
+ pointer_cls = CustomJsonPointer ,
707
713
)
708
714
self .assertTrue (obj is not res )
709
715
self .assertTrue ('baz' in res )
@@ -713,23 +719,23 @@ def test_apply_patch_from_object(self):
713
719
obj = {'foo' : 'bar' }
714
720
res = jsonpatch .apply_patch (
715
721
obj , [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
716
- pointer_cls = self . CustomJsonPointer ,
722
+ pointer_cls = CustomJsonPointer ,
717
723
)
718
724
self .assertTrue (obj is not res )
719
725
720
726
def test_make_patch (self ):
721
727
src = {'foo' : 'bar' , 'boo' : 'qux' }
722
728
dst = {'baz' : 'qux' , 'foo' : 'boo' }
723
729
patch = jsonpatch .make_patch (
724
- src , dst , pointer_cls = self . CustomJsonPointer ,
730
+ src , dst , pointer_cls = CustomJsonPointer ,
725
731
)
726
732
res = patch .apply (src )
727
733
self .assertTrue (src is not res )
728
- self .assertEqual (patch .pointer_cls , self . CustomJsonPointer )
734
+ self .assertEqual (patch .pointer_cls , CustomJsonPointer )
729
735
self .assertTrue (patch ._ops )
730
736
for op in patch ._ops :
731
- self .assertIsInstance (op .pointer , self . CustomJsonPointer )
732
- self .assertEqual (op .pointer_cls , self . CustomJsonPointer )
737
+ self .assertIsInstance (op .pointer , CustomJsonPointer )
738
+ self .assertEqual (op .pointer_cls , CustomJsonPointer )
733
739
734
740
def test_operations (self ):
735
741
patch = jsonpatch .JsonPatch ([
@@ -740,22 +746,18 @@ def test_operations(self):
740
746
{'op' : 'test' , 'path' : '/baz' , 'value' : [1 , 3 ]},
741
747
{'op' : 'replace' , 'path' : '/baz/0' , 'value' : 42 },
742
748
{'op' : 'remove' , 'path' : '/baz/1' },
743
- ], pointer_cls = self . CustomJsonPointer )
749
+ ], pointer_cls = CustomJsonPointer )
744
750
self .assertEqual (patch .apply ({}), {'baz' : [42 ]})
745
- self .assertEqual (patch .pointer_cls , self . CustomJsonPointer )
751
+ self .assertEqual (patch .pointer_cls , CustomJsonPointer )
746
752
self .assertTrue (patch ._ops )
747
753
for op in patch ._ops :
748
- self .assertIsInstance (op .pointer , self .CustomJsonPointer )
749
- self .assertEqual (op .pointer_cls , self .CustomJsonPointer )
750
-
751
- class PrefixJsonPointer (jsonpointer .JsonPointer ):
752
- def __init__ (self , pointer ):
753
- super ().__init__ ('/foo/bar' + pointer )
754
+ self .assertIsInstance (op .pointer , CustomJsonPointer )
755
+ self .assertEqual (op .pointer_cls , CustomJsonPointer )
754
756
755
757
def test_json_patch_wtih_prefix_pointer (self ):
756
758
res = jsonpatch .apply_patch (
757
759
{'foo' : {'bar' : {}}}, [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
758
- pointer_cls = self . PrefixJsonPointer ,
760
+ pointer_cls = PrefixJsonPointer ,
759
761
)
760
762
self .assertEqual (res , {'foo' : {'bar' : {'baz' : 'qux' }}})
761
763
0 commit comments