1
1
from __future__ import unicode_literals , print_function , absolute_import , division , generators , nested_scopes
2
2
import unittest
3
3
4
- from jsonpath_rw import jsonpath # For setting the global auto_id_field flag
4
+ from jsonpath_rw import jsonpath # For setting the global auto_id_field flag
5
5
6
6
from jsonpath_rw .parser import parse
7
7
from jsonpath_rw .jsonpath import *
@@ -37,11 +37,11 @@ def test_DatumInContext_init(self):
37
37
def test_DatumInContext_in_context (self ):
38
38
39
39
assert (DatumInContext (3 ).in_context (path = Fields ('foo' ), context = DatumInContext ('whatever' ))
40
- ==
40
+ ==
41
41
DatumInContext (3 , path = Fields ('foo' ), context = DatumInContext ('whatever' )))
42
42
43
43
assert (DatumInContext (3 ).in_context (path = Fields ('foo' ), context = 'whatever' ).in_context (path = Fields ('baz' ), context = 'whatever' )
44
- ==
44
+ ==
45
45
DatumInContext (3 ).in_context (path = Fields ('foo' ), context = DatumInContext ('whatever' ).in_context (path = Fields ('baz' ), context = 'whatever' )))
46
46
47
47
# def test_AutoIdForDatum_pseudopath(self):
@@ -141,10 +141,10 @@ def test_slice_value(self):
141
141
142
142
# Funky slice hacks
143
143
self .check_cases ([
144
- ('[*]' , 1 , [1 ]), # This is a funky hack
145
- ('[0:]' , 1 , [1 ]), # This is a funky hack
146
- ('[*]' , {'foo' :1 }, [{'foo' : 1 }]), # This is a funky hack
147
- ('[*].foo' , {'foo' :1 }, [1 ]), # This is a funky hack
144
+ ('[*]' , 1 , [1 ]), # This is a funky hack
145
+ ('[0:]' , 1 , [1 ]), # This is a funky hack
146
+ ('[*]' , {'foo' :1 }, [{'foo' : 1 }]), # This is a funky hack
147
+ ('[*].foo' , {'foo' :1 }, [1 ]), # This is a funky hack
148
148
])
149
149
150
150
def test_child_value (self ):
@@ -154,8 +154,8 @@ def test_child_value(self):
154
154
155
155
def test_descendants_value (self ):
156
156
self .check_cases ([
157
- ('foo..baz' , {'foo' : {'baz' : 1 , 'bing' : {'baz' : 2 }}}, [1 , 2 ] ),
158
- ('foo..baz' , {'foo' : [{'baz' : 1 }, {'baz' : 2 }]}, [1 , 2 ] ),
157
+ ('foo..baz' , {'foo' : {'baz' : 1 , 'bing' : {'baz' : 2 }}}, [1 , 2 ]),
158
+ ('foo..baz' , {'foo' : [{'baz' : 1 }, {'baz' : 2 }]}, [1 , 2 ]),
159
159
])
160
160
161
161
def test_parent_value (self ):
@@ -165,7 +165,7 @@ def test_parent_value(self):
165
165
def test_hyphen_key (self ):
166
166
self .check_cases ([('foo.bar-baz' , {'foo' : {'bar-baz' : 3 }}, [3 ]),
167
167
('foo.[bar-baz,blah-blah]' , {'foo' : {'bar-baz' : 3 , 'blah-blah' :5 }},
168
- [3 ,5 ])])
168
+ [3 , 5 ])])
169
169
self .assertRaises (JsonPathLexerError , self .check_cases ,
170
170
[('foo.-baz' , {'foo' : {'-baz' : 8 }}, [8 ])])
171
171
@@ -229,7 +229,7 @@ def test_child_paths(self):
229
229
('foo.baz.bizzle' , {'foo' : {'baz' : {'bizzle' : 5 }}}, ['foo.baz.bizzle' ])])
230
230
231
231
def test_descendants_paths (self ):
232
- self .check_paths ([('foo..baz' , {'foo' : {'baz' : 1 , 'bing' : {'baz' : 2 }}}, ['foo.baz' , 'foo.bing.baz' ] )])
232
+ self .check_paths ([('foo..baz' , {'foo' : {'baz' : 1 , 'bing' : {'baz' : 2 }}}, ['foo.baz' , 'foo.bing.baz' ])])
233
233
234
234
235
235
#
@@ -240,23 +240,23 @@ def test_fields_auto_id(self):
240
240
self .check_cases ([ ('foo.id' , {'foo' : 'baz' }, ['foo' ]),
241
241
('foo.id' , {'foo' : {'id' : 'baz' }}, ['baz' ]),
242
242
('foo,baz.id' , {'foo' : 1 , 'baz' : 2 }, ['foo' , 'baz' ]),
243
- ('*.id' ,
243
+ ('*.id' ,
244
244
{'foo' :{'id' : 1 },
245
245
'baz' : 2 },
246
246
set (['1' , 'baz' ])) ])
247
247
248
248
def test_root_auto_id (self ):
249
249
jsonpath .auto_id_field = 'id'
250
250
self .check_cases ([
251
- ('$.id' , {'foo' : 'baz' }, ['$' ]), # This is a wonky case that is not that interesting
252
- ('foo.$.id' , {'foo' : 'baz' , 'id' : 'bizzle' }, ['bizzle' ]),
251
+ ('$.id' , {'foo' : 'baz' }, ['$' ]), # This is a wonky case that is not that interesting
252
+ ('foo.$.id' , {'foo' : 'baz' , 'id' : 'bizzle' }, ['bizzle' ]),
253
253
('foo.$.baz.id' , {'foo' : 4 , 'baz' : 3 }, ['baz' ]),
254
254
])
255
255
256
256
def test_this_auto_id (self ):
257
257
jsonpath .auto_id_field = 'id'
258
258
self .check_cases ([
259
- ('id' , {'foo' : 'baz' }, ['`this`' ]), # This is, again, a wonky case that is not that interesting
259
+ ('id' , {'foo' : 'baz' }, ['`this`' ]), # This is, again, a wonky case that is not that interesting
260
260
('foo.`this`.id' , {'foo' : 'baz' }, ['foo' ]),
261
261
('foo.`this`.baz.id' , {'foo' : {'baz' : 3 }}, ['foo.baz' ]),
262
262
])
@@ -281,12 +281,12 @@ def test_child_auto_id(self):
281
281
282
282
def test_descendants_auto_id (self ):
283
283
jsonpath .auto_id_field = "id"
284
- self .check_cases ([('foo..baz.id' ,
284
+ self .check_cases ([('foo..baz.id' ,
285
285
{'foo' : {
286
- 'baz' : 1 ,
286
+ 'baz' : 1 ,
287
287
'bing' : {
288
288
'baz' : 2
289
289
}
290
290
} },
291
- ['foo.baz' ,
292
- 'foo.bing.baz' ] )])
291
+ ['foo.baz' ,
292
+ 'foo.bing.baz' ])])
0 commit comments