@@ -671,39 +671,45 @@ def test_create_with_pointer(self):
671671 self .assertEqual (result , expected )
672672
673673
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 )
675681
676- class CustomJsonPointer ( jsonpointer . JsonPointer ):
677- pass
682+
683+ class CustomJsonPointerTests ( unittest . TestCase ):
678684
679685 def test_json_patch_from_string (self ):
680686 patch = '[{"op": "add", "path": "/baz", "value": "qux"}]'
681687 res = jsonpatch .JsonPatch .from_string (
682- patch , pointer_cls = self . CustomJsonPointer ,
688+ patch , pointer_cls = CustomJsonPointer ,
683689 )
684- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
690+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
685691
686692 def test_json_patch_from_object (self ):
687693 patch = [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
688694 res = jsonpatch .JsonPatch (
689- patch , pointer_cls = self . CustomJsonPointer ,
695+ patch , pointer_cls = CustomJsonPointer ,
690696 )
691- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
697+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
692698
693699 def test_json_patch_from_diff (self ):
694700 old = {'foo' : 'bar' }
695701 new = {'foo' : 'baz' }
696702 res = jsonpatch .JsonPatch .from_diff (
697- old , new , pointer_cls = self . CustomJsonPointer ,
703+ old , new , pointer_cls = CustomJsonPointer ,
698704 )
699- self .assertEqual (res .pointer_cls , self . CustomJsonPointer )
705+ self .assertEqual (res .pointer_cls , CustomJsonPointer )
700706
701707 def test_apply_patch_from_string (self ):
702708 obj = {'foo' : 'bar' }
703709 patch = '[{"op": "add", "path": "/baz", "value": "qux"}]'
704710 res = jsonpatch .apply_patch (
705711 obj , patch ,
706- pointer_cls = self . CustomJsonPointer ,
712+ pointer_cls = CustomJsonPointer ,
707713 )
708714 self .assertTrue (obj is not res )
709715 self .assertTrue ('baz' in res )
@@ -713,23 +719,23 @@ def test_apply_patch_from_object(self):
713719 obj = {'foo' : 'bar' }
714720 res = jsonpatch .apply_patch (
715721 obj , [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
716- pointer_cls = self . CustomJsonPointer ,
722+ pointer_cls = CustomJsonPointer ,
717723 )
718724 self .assertTrue (obj is not res )
719725
720726 def test_make_patch (self ):
721727 src = {'foo' : 'bar' , 'boo' : 'qux' }
722728 dst = {'baz' : 'qux' , 'foo' : 'boo' }
723729 patch = jsonpatch .make_patch (
724- src , dst , pointer_cls = self . CustomJsonPointer ,
730+ src , dst , pointer_cls = CustomJsonPointer ,
725731 )
726732 res = patch .apply (src )
727733 self .assertTrue (src is not res )
728- self .assertEqual (patch .pointer_cls , self . CustomJsonPointer )
734+ self .assertEqual (patch .pointer_cls , CustomJsonPointer )
729735 self .assertTrue (patch ._ops )
730736 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 )
733739
734740 def test_operations (self ):
735741 patch = jsonpatch .JsonPatch ([
@@ -740,22 +746,18 @@ def test_operations(self):
740746 {'op' : 'test' , 'path' : '/baz' , 'value' : [1 , 3 ]},
741747 {'op' : 'replace' , 'path' : '/baz/0' , 'value' : 42 },
742748 {'op' : 'remove' , 'path' : '/baz/1' },
743- ], pointer_cls = self . CustomJsonPointer )
749+ ], pointer_cls = CustomJsonPointer )
744750 self .assertEqual (patch .apply ({}), {'baz' : [42 ]})
745- self .assertEqual (patch .pointer_cls , self . CustomJsonPointer )
751+ self .assertEqual (patch .pointer_cls , CustomJsonPointer )
746752 self .assertTrue (patch ._ops )
747753 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 )
754756
755757 def test_json_patch_wtih_prefix_pointer (self ):
756758 res = jsonpatch .apply_patch (
757759 {'foo' : {'bar' : {}}}, [{'op' : 'add' , 'path' : '/baz' , 'value' : 'qux' }],
758- pointer_cls = self . PrefixJsonPointer ,
760+ pointer_cls = PrefixJsonPointer ,
759761 )
760762 self .assertEqual (res , {'foo' : {'bar' : {'baz' : 'qux' }}})
761763
0 commit comments