@@ -81,7 +81,8 @@ class TestJsonPath(unittest.TestCase):
8181
8282 @classmethod
8383 def setup_class (cls ):
84- logging .basicConfig ()
84+ logging .basicConfig (format = '%(levelname)s:%(funcName)s:%(message)s' ,
85+ level = logging .DEBUG )
8586
8687 #
8788 # Check that the data value returned is good
@@ -91,7 +92,7 @@ def check_cases(self, test_cases):
9192 # Also, we coerce iterables, etc, into the desired target type
9293
9394 for string , data , target in test_cases :
94- print ('parse("%s").find(%s) =?= %s' % (string , data , target ))
95+ logging . debug ('parse("%s").find(%s) =?= %s' % (string , data , target ))
9596 result = parse (string ).find (data )
9697 if isinstance (target , list ):
9798 assert [r .value for r in result ] == target
@@ -102,10 +103,12 @@ def check_cases(self, test_cases):
102103
103104 def test_fields_value (self ):
104105 jsonpath .auto_id_field = None
105- self .check_cases ([ ('foo' , {'foo' : 'baz' }, ['baz' ]),
106- ('foo,baz' , {'foo' : 1 , 'baz' : 2 }, [1 , 2 ]),
107- ('@foo' , {'@foo' : 1 }, [1 ]),
108- ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 ])) ])
106+ self .check_cases ([
107+ ('foo' , {'foo' : 'baz' }, ['baz' ]),
108+ ('foo,baz' , {'foo' : 1 , 'baz' : 2 }, [1 , 2 ]),
109+ ('@foo' , {'@foo' : 1 }, [1 ]),
110+ ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 ]))
111+ ])
109112
110113 jsonpath .auto_id_field = 'id'
111114 self .check_cases ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 , '`this`' ])) ])
@@ -182,7 +185,7 @@ def check_paths(self, test_cases):
182185 # Also, we coerce iterables, etc, into the desired target type
183186
184187 for string , data , target in test_cases :
185- print ('parse("%s").find(%s).paths =?= %s' % (string , data , target ))
188+ logging . debug ('parse("%s").find(%s).paths =?= %s' % (string , data , target ))
186189 result = parse (string ).find (data )
187190 if isinstance (target , list ):
188191 assert [str (r .full_path ) for r in result ] == target
@@ -294,7 +297,7 @@ def test_descendants_auto_id(self):
294297
295298 def check_update_cases (self , test_cases ):
296299 for original , expr_str , value , expected in test_cases :
297- print ('parse(%r).update(%r, %r) =?= %r'
300+ logger . debug ('parse(%r).update(%r, %r) =?= %r'
298301 % (expr_str , original , value , expected ))
299302 expr = parse (expr_str )
300303 actual = expr .update (original , value )
@@ -353,3 +356,30 @@ def test_update_slice(self):
353356 self .check_update_cases ([
354357 (['foo' , 'bar' , 'baz' ], '[0:2]' , 'test' , ['test' , 'test' , 'baz' ])
355358 ])
359+
360+ def check_delete_cases (self , test_cases ):
361+ for string , original , expected in test_cases :
362+ logging .debug ('parse("%s").delete(%s) =?= %s' % (string , original , expected ))
363+ actual = parse (string ).delete (original )
364+ assert actual == expected
365+
366+ def test_delete_fields (self ):
367+ jsonpath .auto_id_field = None
368+ self .check_delete_cases ([
369+ ('foo' , {'foo' : 'baz' }, {}),
370+ ('foo' , {'foo' : 1 , 'baz' : 2 }, {'baz' : 2 }),
371+ ('foo,baz' , {'foo' : 1 , 'baz' : 2 }, {}),
372+ ('@foo' , {'@foo' : 1 }, {}),
373+ ('@foo' , {'@foo' : 1 , 'baz' : 2 }, {'baz' : 2 }),
374+ ('*' , {'foo' : 1 , 'baz' : 2 }, {})
375+ ])
376+
377+ def test_delete_index (self ):
378+ self .check_delete_cases ([
379+ ('[0]' , [42 ], []),
380+ ('[5]' , [42 ], [42 ]),
381+ ('[2]' , [34 , 65 , 29 , 59 ], [34 , 65 , 59 ]),
382+ ('[0]' , None , None ),
383+ ('[0]' , [], []),
384+ ('[0]' , ['foo' , 'bar' , 'baz' ], ['bar' , 'baz' ]),
385+ ])
0 commit comments