@@ -346,6 +346,38 @@ def test_BaseRecording(create_cache_folder):
346346 assert rec2 .get_annotation (annotation_name ) == rec_zarr2_loaded .get_annotation (annotation_name )
347347
348348
349+ def test_json_pickle_equivalence (create_cache_folder ):
350+ """
351+ For a json-ifyable recording, the json and pickle outputs created by `dump` should be the same
352+ (except for the probe information). We check this here for a saved-then-loaded recording,
353+ which tests if relative paths are dealt with in the same way.
354+ """
355+
356+ rec = generate_recording (durations = [1 ])
357+ cache_folder = create_cache_folder
358+
359+ json_file_path = cache_folder / "recording.json"
360+ pkl_file_path = cache_folder / "recording.pkl"
361+
362+ rec .dump (json_file_path , relative_to = cache_folder )
363+ rec .dump (pkl_file_path , relative_to = cache_folder )
364+
365+ with open (json_file_path , "r" ) as f :
366+ data_json = json .load (f )
367+
368+ with open (pkl_file_path , "rb" ) as f :
369+ data_pickle = pickle .load (f )
370+
371+ for key , value in data_json .items ():
372+ # skip probe info, since pickle keeps some additional information
373+ if key not in ["properties" ]:
374+ if isinstance (value , dict ):
375+ for sub_key , sub_value in value .items ():
376+ assert np .all (sub_value == data_pickle [key ][sub_key ])
377+ else :
378+ assert np .all (value == data_pickle [key ])
379+
380+
349381def test_interleaved_probegroups ():
350382 recording = generate_recording (durations = [1.0 ], num_channels = 16 )
351383
0 commit comments