25
25
import testscenarios
26
26
27
27
from jsonpath_ng .ext import parser
28
-
28
+ rest_response1 = {
29
+ "items" :
30
+ [
31
+ {
32
+ "status" : "UP" ,
33
+ "kind" : "compute#region" ,
34
+ "description" : "us-central1" ,
35
+ "quotas" : [
36
+ {"usage" : 3.0 , "metric" : "CPUS" , "limit" : 72.0 },
37
+ {"usage" : 261.0 , "metric" : "DISKS" , "limit" : 40960.0 },
38
+ {"usage" : 0.0 , "metric" : "STATIC" , "limit" : 21.0 },
39
+ {"usage" : 0.0 , "metric" : "IN_USE" , "limit" : 69.0 },
40
+ {"usage" : 0.0 , "metric" : "SSD" , "limit" : 20480.0 }
41
+ ],
42
+ "id" : "1000" ,
43
+ "name" : "us-central1"
44
+ },
45
+ {
46
+ "status" : "UP" ,
47
+ "kind" : "compute#region" ,
48
+ "description" : "us-central2" ,
49
+ "quotas" : [
50
+ {"usage" : 0.0 , "metric" : "CPUS" , "limit" : 72.0 },
51
+ {"usage" : 0.0 , "metric" : "DISKS" , "limit" : 40960.0 },
52
+ {"usage" : 0.0 , "metric" : "STATIC" , "limit" : 21.0 },
53
+ {"usage" : 0.0 , "metric" : "IN_USE" , "limit" : 69.0 },
54
+ {"usage" : 0.0 , "metric" : "SSD" , "limit" : 20480.0 }
55
+ ],
56
+ "id" : "1001" ,
57
+ "name" : "us-central2"
58
+ },
59
+ {
60
+ "status" : "UP" ,
61
+ "kind" : "compute#region" ,
62
+ "description" : "us-central3" ,
63
+ "quotas" : [
64
+ {"usage" : 0.0 , "metric" : "CPUS" , "limit" : 90.0 },
65
+ {"usage" : 0.0 , "metric" : "DISKS" , "limit" : 2040.0 },
66
+ {"usage" : 0.0 , "metric" : "STATIC" , "limit" : 46.0 },
67
+ {"usage" : 0.0 , "metric" : "IN_USE" , "limit" : 80.0 },
68
+ {"usage" : 500.0 , "metric" : "SSD" , "limit" : 20480.0 }
69
+ ],
70
+ "id" : "1002" ,
71
+ "name" : "us-central3"
72
+ }
73
+ ]
74
+ }
29
75
30
76
class Testjsonpath_ng_ext (testscenarios .WithScenarios ,
31
77
base .BaseTestCase ):
@@ -94,6 +140,12 @@ class Testjsonpath_ng_ext(testscenarios.WithScenarios,
94
140
{'cow' : 5 },
95
141
{'cow' : 'neigh' }]},
96
142
target = [{'cow' : 8 }, {'cow' : 7 }])),
143
+ ('filter_gt_negation' , dict (string = 'objects[?!cow<=5]' ,
144
+ data = {'objects' : [{'cow' : 8 },
145
+ {'cow' : 7 },
146
+ {'cow' : 5 },
147
+ {'cow' : 'neigh' }]},
148
+ target = [{'cow' : 8 }, {'cow' : 7 },{'cow' :'neigh' }])),
97
149
('filter_and' , dict (string = 'objects[?cow>5&cat=2]' ,
98
150
data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
99
151
{'cow' : 7 , 'cat' : 2 },
@@ -102,6 +154,85 @@ class Testjsonpath_ng_ext(testscenarios.WithScenarios,
102
154
{'cow' : 8 , 'cat' : 3 }]},
103
155
target = [{'cow' : 8 , 'cat' : 2 },
104
156
{'cow' : 7 , 'cat' : 2 }])),
157
+ ('filter_and_demorgans' , dict (string = 'objects[?!(cow<=5|cat!=2)]' ,
158
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
159
+ {'cow' : 7 , 'cat' : 2 },
160
+ {'cow' : 2 , 'cat' : 2 },
161
+ {'cow' : 5 , 'cat' : 3 },
162
+ {'cow' : 8 , 'cat' : 3 }]},
163
+ target = [{'cow' : 8 , 'cat' : 2 },
164
+ {'cow' : 7 , 'cat' : 2 }])),
165
+ ('filter_or' , dict (string = 'objects[?cow=8|cat=3]' ,
166
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
167
+ {'cow' : 7 , 'cat' : 2 },
168
+ {'cow' : 2 , 'cat' : 2 },
169
+ {'cow' : 5 , 'cat' : 3 },
170
+ {'cow' : 8 , 'cat' : 3 }]},
171
+ target = [{'cow' : 8 , 'cat' : 2 },
172
+ {'cow' : 5 , 'cat' : 3 },
173
+ {'cow' : 8 , 'cat' : 3 }])),
174
+ ('filter_or_demorgans' , dict (string = 'objects[?!(cow!=8&cat!=3)]' ,
175
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
176
+ {'cow' : 7 , 'cat' : 2 },
177
+ {'cow' : 2 , 'cat' : 2 },
178
+ {'cow' : 5 , 'cat' : 3 },
179
+ {'cow' : 8 , 'cat' : 3 }]},
180
+ target = [{'cow' : 8 , 'cat' : 2 },
181
+ {'cow' : 5 , 'cat' : 3 },
182
+ {'cow' : 8 , 'cat' : 3 }])),
183
+ ('filter_or_and' , dict (string = 'objects[?cow=8&cat=2|cat=3]' ,
184
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
185
+ {'cow' : 7 , 'cat' : 2 },
186
+ {'cow' : 2 , 'cat' : 2 },
187
+ {'cow' : 5 , 'cat' : 3 },
188
+ {'cow' : 8 , 'cat' : 3 }]},
189
+ target = [{'cow' : 8 , 'cat' : 2 },
190
+ {'cow' : 5 , 'cat' : 3 },
191
+ {'cow' : 8 , 'cat' : 3 }])),
192
+ ('filter_or_and_overide' , dict (string = 'objects[?cow=8&(cat=2|cat=3)]' ,
193
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 },
194
+ {'cow' : 7 , 'cat' : 2 },
195
+ {'cow' : 2 , 'cat' : 2 },
196
+ {'cow' : 5 , 'cat' : 3 },
197
+ {'cow' : 8 , 'cat' : 3 }]},
198
+ target = [{'cow' : 8 , 'cat' : 2 },
199
+ {'cow' : 8 , 'cat' : 3 }])),
200
+ ('filter_or_and' , dict (string = 'objects[?dog=1|cat=3&cow=8]' ,
201
+ data = {'objects' : [{'cow' : 8 , 'cat' : 2 , 'dog' :1 },
202
+ {'cow' : 7 , 'cat' : 2 },
203
+ {'cow' : 2 , 'cat' : 2 },
204
+ {'cow' : 5 , 'cat' : 3 },
205
+ {'cow' : 8 , 'cat' : 3 }]},
206
+ target = [{'cow' : 8 , 'cat' : 2 , 'dog' :1 },
207
+ {'cow' : 8 , 'cat' : 3 }])),
208
+ ('filter_complex' , dict (string = '$.items[?((!(val==4))&(id==2))|(!((id!=1)&(id!=3)))]' ,
209
+ data = {"items" :[{"id" :1 , "val" :1 , "info" :1 },{"id" :2 , "val" :4 },{"id" :2 ,"val" :2 },{"id" :3 ,"val" :3 }]},
210
+ target = [{'info' : 1 , 'id' : 1 , 'val' : 1 },
211
+ {'id' : 2 , 'val' : 2 },
212
+ {'id' : 3 , 'val' : 3 }])),
213
+ ('filter_complex2' , dict (string = "$.items[?(@.quotas[?((@.metric='SSD' & @.usage>0) | (@.metric='CPU' & @.usage>0) | (@.metric='DISKS' & @.usage>0))])]" ,
214
+ data = rest_response1 ,
215
+ target = [{'description' : 'us-central1' ,
216
+ 'id' : '1000' ,
217
+ 'kind' : 'compute#region' ,
218
+ 'name' : 'us-central1' ,
219
+ 'quotas' : [{'limit' : 72.0 , 'metric' : 'CPUS' , 'usage' : 3.0 },
220
+ {'limit' : 40960.0 , 'metric' : 'DISKS' , 'usage' : 261.0 },
221
+ {'limit' : 21.0 , 'metric' : 'STATIC' , 'usage' : 0.0 },
222
+ {'limit' : 69.0 , 'metric' : 'IN_USE' , 'usage' : 0.0 },
223
+ {'limit' : 20480.0 , 'metric' : 'SSD' , 'usage' : 0.0 }],
224
+ 'status' : 'UP' },
225
+ {'description' : 'us-central3' ,
226
+ 'id' : '1002' ,
227
+ 'kind' : 'compute#region' ,
228
+ 'name' : 'us-central3' ,
229
+ 'quotas' : [{'limit' : 90.0 , 'metric' : 'CPUS' , 'usage' : 0.0 },
230
+ {'limit' : 2040.0 , 'metric' : 'DISKS' , 'usage' : 0.0 },
231
+ {'limit' : 46.0 , 'metric' : 'STATIC' , 'usage' : 0.0 },
232
+ {'limit' : 80.0 , 'metric' : 'IN_USE' , 'usage' : 0.0 },
233
+ {'limit' : 20480.0 , 'metric' : 'SSD' , 'usage' : 500.0 }],
234
+ 'status' : 'UP' }])),
235
+
105
236
('filter_float_gt' , dict (
106
237
string = 'objects[?confidence>=0.5].prediction' ,
107
238
data = {
0 commit comments