diff --git a/cellfinder/napari/curation.py b/cellfinder/napari/curation.py index 2dfc7d92..f7645e4f 100644 --- a/cellfinder/napari/curation.py +++ b/cellfinder/napari/curation.py @@ -495,24 +495,29 @@ def check_image_data_for_extraction(self) -> bool: return False def check_training_data_exists(self) -> bool: + """ + Returns true if both training layers exist, and have len > 0. + Otherwise displays useful explanatory info and returns False. + """ if not ( - self.training_data_cell_layer or self.training_data_non_cell_layer + self.training_data_cell_layer and self.training_data_non_cell_layer ): show_info( "No training data layers have been added. " - "Please add a layer and annotate some points.", + "Please add layers for both cells and non-cells," + "and annotate some points in both.", ) return False else: if ( len(self.training_data_cell_layer.data) > 0 - or len(self.training_data_non_cell_layer.data) > 0 + and len(self.training_data_non_cell_layer.data) > 0 ): return True else: show_info( "No training data points have been added. " - "Please annotate some points.", + "Please annotate points in both training data layers.", ) return False diff --git a/tests/napari/test_curation.py b/tests/napari/test_curation.py index 083f90fa..36516e5c 100644 --- a/tests/napari/test_curation.py +++ b/tests/napari/test_curation.py @@ -210,3 +210,26 @@ def test_check_layer_removal_sync(valid_curation_widget): assert valid_curation_widget.background_layer is None assert valid_curation_widget.training_data_cell_layer is None assert valid_curation_widget.training_data_non_cell_layer is None + + +@pytest.mark.xfail(reason="See discussion in #443", raises=AssertionError) +@pytest.mark.parametrize( + "layer_indices_to_remove", + [[-2], [-3], [-2, -3]], + ids=( + "users deletes non-cell training data layer", + "user deletes cell training data layer", + "user deletes both", + ), +) +def test_training_data_does_not_exist_when_user_removes_layers( + valid_curation_widget, layer_indices_to_remove +): + for layer in layer_indices_to_remove: + valid_curation_widget.viewer.layers.pop(layer) + assert not valid_curation_widget.check_training_data_exists() + + +@pytest.mark.xfail(reason="See discussion in #443", raises=AssertionError) +def test_valid_widget_has_valid_training_data(valid_curation_widget): + assert valid_curation_widget.check_training_data_exists()