@@ -81,7 +81,8 @@ class TestJsonPath(unittest.TestCase):
81
81
82
82
@classmethod
83
83
def setup_class (cls ):
84
- logging .basicConfig ()
84
+ logging .basicConfig (format = '%(levelname)s:%(funcName)s:%(message)s' ,
85
+ level = logging .DEBUG )
85
86
86
87
#
87
88
# Check that the data value returned is good
@@ -91,7 +92,7 @@ def check_cases(self, test_cases):
91
92
# Also, we coerce iterables, etc, into the desired target type
92
93
93
94
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 ))
95
96
result = parse (string ).find (data )
96
97
if isinstance (target , list ):
97
98
assert [r .value for r in result ] == target
@@ -102,10 +103,12 @@ def check_cases(self, test_cases):
102
103
103
104
def test_fields_value (self ):
104
105
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
+ ])
109
112
110
113
jsonpath .auto_id_field = 'id'
111
114
self .check_cases ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 , '`this`' ])) ])
@@ -182,7 +185,7 @@ def check_paths(self, test_cases):
182
185
# Also, we coerce iterables, etc, into the desired target type
183
186
184
187
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 ))
186
189
result = parse (string ).find (data )
187
190
if isinstance (target , list ):
188
191
assert [str (r .full_path ) for r in result ] == target
@@ -294,7 +297,7 @@ def test_descendants_auto_id(self):
294
297
295
298
def check_update_cases (self , test_cases ):
296
299
for original , expr_str , value , expected in test_cases :
297
- print ('parse(%r).update(%r, %r) =?= %r'
300
+ logge
57AE
r . debug ('parse(%r).update(%r, %r) =?= %r'
298
301
% (expr_str , original , value , expected ))
299
302
expr = parse (expr_str )
300
303
actual = expr .update (original , value )
@@ -353,3 +356,30 @@ def test_update_slice(self):
353
356
self .check_update_cases ([
354
357
(['foo' , 'bar' , 'baz' ], '[0:2]' , 'test' , ['test' , 'test' , 'baz' ])
355
358
])
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