@@ -572,6 +572,69 @@ def test_background_params_value_indices(self, test_problem, bad_value, request)
572572 check_indices (test_problem )
573573
574574
575+ @pytest .mark .parametrize ("test_project" , ["standard_layers_project" , "custom_xy_project" , "domains_project" ])
576+ @pytest .mark .parametrize ("field" , ["data" , "background" , "bulk_in" , "bulk_out" , "scalefactor" , "resolution" ])
577+ def test_undefined_contrast_fields (test_project , field , request ):
578+ """If a field in a contrast is empty, we should raise an error."""
579+ test_project = request .getfixturevalue (test_project )
580+ setattr (test_project .contrasts [0 ], field , "" )
581+
582+ with pytest .raises (
583+ ValueError ,
584+ match = f'In the input project, the "{ field } " field of contrast '
585+ f'"{ test_project .contrasts [0 ].name } " does not have a value defined. '
586+ f"A value must be supplied before running the project." ,
587+ ):
588+ make_problem (test_project )
589+
590+
591+ @pytest .mark .parametrize ("test_project" , ["standard_layers_project" , "custom_xy_project" , "domains_project" ])
592+ def test_undefined_background (test_project , request ):
593+ """If the source field of a background defined in a contrast is empty, we should raise an error."""
594+ test_project = request .getfixturevalue (test_project )
595+ background = test_project .backgrounds [test_project .contrasts [0 ].background ]
596+ background .source = ""
597+
598+ with pytest .raises (
599+ ValueError ,
600+ match = f"All backgrounds must have a source defined. For a { background .type } type "
601+ f"background, the source must be defined in "
602+ f'"{ RATapi .project .values_defined_in [f"backgrounds.{ background .type } .source" ]} "' ,
603+ ):
604+ make_problem (test_project )
605+
606+
607+ @pytest .mark .parametrize ("test_project" , ["standard_layers_project" , "custom_xy_project" , "domains_project" ])
608+ def test_undefined_resolution (test_project , request ):
609+ """If the source field of a resolution defined in a contrast is empty, we should raise an error."""
610+ test_project = request .getfixturevalue (test_project )
611+ resolution = test_project .resolutions [test_project .contrasts [0 ].resolution ]
612+ resolution .source = ""
613+
614+ with pytest .raises (
615+ ValueError ,
616+ match = f"Constant resolutions must have a source defined. The source must be defined in "
617+ f'"{ RATapi .project .values_defined_in [f"resolutions.{ resolution .type } .source" ]} "' ,
618+ ):
619+ make_problem (test_project )
620+
621+
622+ @pytest .mark .parametrize ("test_project" , ["standard_layers_project" , "domains_project" ])
623+ @pytest .mark .parametrize ("field" , ["thickness" , "SLD" , "roughness" ])
624+ def test_undefined_layers (test_project , field , request ):
625+ """If the thickness, SLD, or roughness fields of a layer defined in the project are empty, we should raise an
626+ error."""
627+ test_project = request .getfixturevalue (test_project )
628+ setattr (test_project .layers [0 ], field , "" )
629+
630+ with pytest .raises (
631+ ValueError ,
632+ match = f'In the input project, the "{ field } " field of layer { test_project .layers [0 ].name } '
633+ f"does not have a value defined. A value must be supplied before running the project." ,
634+ ):
635+ make_problem (test_project )
636+
637+
575638def test_append_data_background ():
576639 """Test that background data is correctly added to contrast data."""
577640 data = np .array ([[1 , 2 , 3 ], [4 , 5 , 6 ], [7 , 8 , 9 ]])
0 commit comments