@@ -191,6 +191,137 @@ def test_non_homogeneous_list(self):
191
191
sm .match ("key1" , [{"key2" : "value1" }, "value2" , 3 ])
192
192
sm ._assert_all ()
193
193
194
+ def test_list_as_last_node_in_skip_verification_path (self ):
195
+ sm = SnapshotSession (scope_key = "A" , verify = True , base_file_path = "" , update = False )
196
+ sm .recorded_state = {"key_a" : {"aaa" : ["item1" , "item2" , "item3" ]}}
197
+ sm .match (
198
+ "key_a" ,
199
+ {"aaa" : ["item1" , "different-value" ]},
200
+ )
201
+
202
+ with pytest .raises (Exception ) as ctx : # asserts it fail without skipping
203
+ sm ._assert_all ()
204
+ ctx .match ("Parity snapshot failed" )
205
+
206
+ skip_path = ["$..aaa[1]" , "$..aaa[2]" ]
207
+ sm ._assert_all (skip_verification_paths = skip_path )
208
+
209
+ skip_path = ["$..aaa.1" , "$..aaa.2" ]
210
+ sm ._assert_all (skip_verification_paths = skip_path )
211
+
212
+ def test_list_as_last_node_in_skip_verification_path_complex (self ):
213
+ sm = SnapshotSession (scope_key = "A" , verify = True , base_file_path = "" , update = False )
214
+ sm .recorded_state = {
215
+ "key_a" : {
216
+ "aaa" : [
217
+ {"aab" : ["aac" , "aad" ]},
218
+ {"aab" : ["aac" , "aad" ]},
219
+ {"aab" : ["aac" , "aad" ]},
220
+ ]
221
+ }
222
+ }
223
+ sm .match (
224
+ "key_a" ,
225
+ {
226
+ "aaa" : [
227
+ {"aab" : ["aac" , "bad-value" ], "bbb" : "value" },
228
+ {"aab" : ["aac" , "aad" , "bad-value" ]},
229
+ {"aab" : ["bad-value" , "aad" ]},
230
+ ]
231
+ },
232
+ )
233
+
234
+ with pytest .raises (Exception ) as ctx : # asserts it fail without skipping
235
+ sm ._assert_all ()
236
+ ctx .match ("Parity snapshot failed" )
237
+
238
+ skip_path = [
239
+ "$..aaa[0].aab[1]" ,
240
+ "$..aaa[0].bbb" ,
241
+ "$..aaa[1].aab[2]" ,
242
+ "$..aaa[2].aab[0]" ,
243
+ ]
244
+ sm ._assert_all (skip_verification_paths = skip_path )
245
+
246
+ skip_path = [
247
+ "$..aaa.0..aab.1" ,
248
+ "$..aaa.0..bbb" ,
249
+ "$..aaa.1..aab.2" ,
250
+ "$..aaa.2..aab.0" ,
251
+ ]
252
+ sm ._assert_all (skip_verification_paths = skip_path )
253
+
254
+ def test_list_as_mid_node_in_skip_verification_path (self ):
255
+ sm = SnapshotSession (scope_key = "A" , verify = True , base_file_path = "" , update = False )
256
+ sm .recorded_state = {"key_a" : {"aaa" : [{"aab" : "value1" }, {"aab" : "value2" }]}}
257
+ sm .match (
258
+ "key_a" ,
259
+ {"aaa" : [{"aab" : "value1" }, {"aab" : "bad-value" }]},
260
+ )
261
+
262
+ with pytest .raises (Exception ) as ctx : # asserts it fail without skipping
263
+ sm ._assert_all ()
264
+ ctx .match ("Parity snapshot failed" )
265
+
266
+ skip_path = ["$..aaa[1].aab" ]
267
+ sm ._assert_all (skip_verification_paths = skip_path )
268
+
269
+ skip_path = ["$..aaa.1.aab" ]
270
+ sm ._assert_all (skip_verification_paths = skip_path )
271
+
272
+ def test_list_as_last_node_in_skip_verification_path_nested (self ):
273
+ sm = SnapshotSession (scope_key = "A" , verify = True , base_file_path = "" , update = False )
274
+ sm .recorded_state = {
275
+ "key_a" : {
276
+ "aaa" : [
277
+ "bbb" ,
278
+ "ccc" ,
279
+ [
280
+ "ddd" ,
281
+ "eee" ,
282
+ [
283
+ "fff" ,
284
+ "ggg" ,
285
+ ],
286
+ ],
287
+ ]
288
+ }
289
+ }
290
+ sm .match (
291
+ "key_a" ,
292
+ {
293
+ "aaa" : [
294
+ "bbb" ,
295
+ "ccc" ,
296
+ [
297
+ "bad-value" ,
298
+ "eee" ,
299
+ [
300
+ "fff" ,
301
+ "ggg" ,
302
+ ],
303
+ ],
304
+ ]
305
+ },
306
+ )
307
+
308
+ with pytest .raises (Exception ) as ctx : # asserts it fail without skipping
309
+ sm ._assert_all ()
310
+ ctx .match ("Parity snapshot failed" )
311
+
312
+ skip_path = ["$..aaa[2][0]" ]
313
+ sm ._assert_all (skip_verification_paths = skip_path )
314
+
315
+ skip_path = ["$..aaa.2[0]" ]
316
+ sm ._assert_all (skip_verification_paths = skip_path )
317
+
318
+ # these 2 will actually skip almost everything, as they will match every first element of any list inside `aaa`
319
+ skip_path = ["$..aaa..[0]" ]
320
+ sm ._assert_all (skip_verification_paths = skip_path )
321
+
322
+ skip_path = ["$..aaa..0" ]
323
+ sm ._assert_all (skip_verification_paths = skip_path )
324
+
194
325
195
326
def test_json_diff_format ():
196
327
path = ["Records" , 1 ]
0 commit comments