@@ -191,6 +191,135 @@ 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" , "eee" ,
281
+ [
282
+ "fff" ,
283
+ "ggg" ,
284
+ ]
285
+ ]
286
+ ]
287
+ }
288
+ }
289
+ sm .match (
290
+ "key_a" ,
291
+ {
292
+ "aaa" : [
293
+ "bbb" ,
294
+ "ccc" ,
295
+ [
296
+ "bad-value" , "eee" ,
297
+ [
298
+ "fff" ,
299
+ "ggg" ,
300
+ ]
301
+ ]
302
+ ]
303
+ },
304
+ )
305
+
306
+ with pytest .raises (Exception ) as ctx : # asserts it fail without skipping
307
+ sm ._assert_all ()
308
+ ctx .match ("Parity snapshot failed" )
309
+
310
+ skip_path = ["$..aaa[2][0]" ]
311
+ sm ._assert_all (skip_verification_paths = skip_path )
312
+
313
+ skip_path = ["$..aaa.2[0]" ]
314
+ sm ._assert_all (skip_verification_paths = skip_path )
315
+
316
+ # these 2 will actually skip almost everything, as they will match every first element of any list inside `aaa`
317
+ skip_path = ["$..aaa..[0]" ]
318
+ sm ._assert_all (skip_verification_paths = skip_path )
319
+
320
+ skip_path = ["$..aaa..0" ]
321
+ sm ._assert_all (skip_verification_paths = skip_path )
322
+
194
323
195
324
def test_json_diff_format ():
196
325
path = ["Records" , 1 ]
0 commit comments