@@ -327,6 +327,35 @@ def test_write_session_with_transducer_tracking_results(example_database: Databa
327327 session .transducer_tracking_results = [example_transducer_tracking_result ]
328328 example_database .write_session (example_subject , session , on_conflict = OnConflictOpts .OVERWRITE )
329329
330+ def test_delete_session (example_database : Database , example_subject : Subject ):
331+ # Write a session
332+ session = Session (name = "bleh" , id = 'a_session' ,subject_id = example_subject .id )
333+
334+ session_id = session .id
335+ subject_id = example_subject .id
336+
337+ # Can add a new session, and it loads back in correctly.
338+ example_database .write_session (example_subject , session )
339+
340+ assert session .id in example_database .get_session_ids (example_subject .id )
341+
342+ # Session is deleted
343+ example_database .delete_session (subject_id , session_id )
344+ assert session .id not in example_database .get_session_ids (subject_id )
345+ with pytest .raises (FileNotFoundError ):
346+ example_database .load_session (example_subject , session_id )
347+
348+ # Error option
349+ with pytest .raises (ValueError , match = "does not exist in the database" ):
350+ example_database .delete_session (subject_id , "non_existent_protocol" , on_conflict = OnConflictOpts .ERROR )
351+
352+ # Skip option
353+ example_database .delete_session (subject_id , "non_existent_protocol" , on_conflict = OnConflictOpts .SKIP )
354+
355+ # Invalid option
356+ with pytest .raises (ValueError , match = "Invalid" ):
357+ example_database .delete_session (subject_id , "non_existent_protocol" , on_conflict = OnConflictOpts .OVERWRITE )
358+
330359def test_write_run (example_database : Database , tmp_path :Path ):
331360 subject_id = "example_subject"
332361 session_id = "example_session"
0 commit comments