@@ -884,6 +884,54 @@ def test_validate_calibration_object_tags(self):
884884 )
885885 self .assertIsNotNone (metadata )
886886
887+ def test_validate_subject_details_if_not_specimen (self ):
888+ """Tests that subject details are required if acquisition.specimen_id is not provided"""
889+
890+ # Case where specimen_id is provided - should pass without subject_details
891+ acquisition_with_specimen = Acquisition .model_construct (
892+ instrument_id = "Test" ,
893+ subject_id = "123456" ,
894+ specimen_id = "123456-001" ,
895+ data_streams = [],
896+ )
897+ metadata_with_specimen = Metadata (
898+ name = "Test Metadata" ,
899+ location = "Test Location" ,
900+ subject = subject ,
901+ acquisition = acquisition_with_specimen ,
902+ )
903+ self .assertIsNotNone (metadata_with_specimen )
904+
905+ # Case where specimen_id is not provided and subject_details is provided - should pass
906+ acquisition_with_details = Acquisition .model_construct (
907+ instrument_id = "Test" ,
908+ subject_id = "123456" ,
909+ data_streams = [],
910+ subject_details = AcquisitionSubjectDetails .model_construct (),
911+ )
912+ metadata_with_details = Metadata (
913+ name = "Test Metadata" ,
914+ location = "Test Location" ,
915+ subject = subject ,
916+ acquisition = acquisition_with_details ,
917+ )
918+ self .assertIsNotNone (metadata_with_details )
919+
920+ # Case where neither specimen_id nor subject_details is provided - should fail
921+ acquisition_missing_both = Acquisition .model_construct (
922+ subject_id = "123456" ,
923+ instrument_id = "Test" ,
924+ data_streams = [],
925+ )
926+ with self .assertRaises (ValueError ) as context :
927+ Metadata (
928+ name = "Test Metadata" ,
929+ location = "Test Location" ,
930+ subject = subject ,
931+ acquisition = acquisition_missing_both ,
932+ )
933+ self .assertIn ("Acquisition.subject_details are required for in vivo experiments" , str (context .exception ))
934+
887935
888936if __name__ == "__main__" :
889937 unittest .main ()
0 commit comments