@@ -108,6 +108,22 @@ def test_fields_value(self):
108
108
jsonpath .auto_id_field = 'id'
109
109
self .check_cases ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set ([1 , 2 , '@' ])) ])
110
110
111
+ def test_root_value (self ):
112
+ jsonpath .auto_id_field = None
113
+ self .check_cases ([
114
+ ('$' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
115
+ ('foo.$' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
116
+ ('foo.$.foo' , {'foo' : 'baz' }, ['baz' ]),
117
+ ])
118
+
119
+ def test_this_value (self ):
120
+ jsonpath .auto_id_field = None
121
+ self .check_cases ([
122
+ ('@' , {'foo' : 'baz' }, [{'foo' :'baz' }]),
123
+ ('foo.@' , {'foo' : 'baz' }, ['baz' ]),
124
+ ('foo.@.baz' , {'foo' : {'baz' : 3 }}, [3 ]),
125
+ ])
126
+
111
127
def test_index_value (self ):
112
128
self .check_cases ([
113
129
('[0]' , [42 ], [42 ]),
@@ -167,6 +183,22 @@ def test_fields_paths(self):
167
183
jsonpath .auto_id_field = 'id'
168
184
self .check_paths ([ ('*' , {'foo' : 1 , 'baz' : 2 }, set (['foo' , 'baz' , 'id' ])) ])
169
185
186
+ def test_root_paths (self ):
187
+ jsonpath .auto_id_field = None
188
+ self .check_paths ([
189
+ ('$' , {'foo' : 'baz' }, ['$' ]),
190
+ ('foo.$' , {'foo' : 'baz' }, ['$' ]),
191
+ ('foo.$.foo' , {'foo' : 'baz' }, ['foo' ]),
192
+ ])
193
+
194
+ def test_this_paths (self ):
195
+ jsonpath .auto_id_field = None
196
+ self .check_paths ([
197
+ ('@' , {'foo' : 'baz' }, ['@' ]),
198
+ ('foo.@' , {'foo' : 'baz' }, ['foo' ]),
199
+ ('foo.@.baz' , {'foo' : {'baz' : 3 }}, ['foo.baz' ]),
200
+ ])
201
+
170
202
def test_index_paths (self ):
171
203
self .check_paths ([('[0]' , [42 ], ['[0]' ]),
172
204
('[2]' , [34 , 65 , 29 , 59 ], ['[2]' ])])
@@ -197,6 +229,22 @@ def test_fields_auto_id(self):
197
229
'baz' : 2 },
198
230
set (['1' , 'baz' ])) ])
199
231
232
+ def test_root_auto_id (self ):
233
+ jsonpath .auto_id_field = 'id'
234
+ self .check_cases ([
235
+ ('$.id' , {'foo' : 'baz' }, ['$' ]), # This is a wonky case that is not that interesting
236
+ ('foo.$.id' , {'foo' : 'baz' , 'id' : 'bizzle' }, ['bizzle' ]),
237
+ ('foo.$.baz.id' , {'foo' : 4 , 'baz' : 3 }, ['baz' ]),
238
+ ])
239
+
240
+ def test_this_auto_id (self ):
241
+ jsonpath .auto_id_field = 'id'
242
+ self .check_cases ([
243
+ ('id' , {'foo' : 'baz' }, ['@' ]), # This is, again, a wonky case that is not that interesting
244
+ ('foo.@.id' , {'foo' : 'baz' }, ['foo' ]),
245
+ ('foo.@.baz.id' , {'foo' : {'baz' : 3 }}, ['foo.baz' ]),
246
+ ])
247
+
200
248
def test_index_auto_id (self ):
201
249
jsonpath .auto_id_field = "id"
202
250
self .check_cases ([('[0].id' , [42 ], ['[0]' ]),
0 commit comments