Skip to content

Commit

Permalink
trainingView tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hughes036 committed Oct 16, 2023
1 parent 6d2d1dc commit 510d5d5
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 27 deletions.
9 changes: 9 additions & 0 deletions src/allencell_ml_segmenter/_tests/fakes/fake_viewer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from allencell_ml_segmenter.main.i_viewer import IViewer


class FakeViewer(IViewer):
def __init__(self):
self._viewer = None

def add_image(image, name):
pass
78 changes: 63 additions & 15 deletions src/allencell_ml_segmenter/_tests/training/test_view.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,70 @@
# def test_set_patch_size(
# model_selection_widget: ModelSelectionWidget,
# training_model: TrainingModel,
# ) -> None:
# """
# Tests that using the associated combo box properly sets the patch size field.
# """

# for index, patch in enumerate(PatchSize):
# # ACT
# model_selection_widget._patch_size_combo_box.setCurrentIndex(index)

# # ASSERT
# assert training_model.get_patch_size() == patch
from allencell_ml_segmenter._tests.fakes.fake_viewer import FakeViewer
from allencell_ml_segmenter._tests.fakes.fake_experiments_model import (
FakeExperimentsModel,
)
from allencell_ml_segmenter.main.main_model import MainModel
from allencell_ml_segmenter.training.training_model import (
PatchSize,
TrainingModel,
)
from allencell_ml_segmenter.training.view import TrainingView
import pytest
from pytestqt.qtbot import QtBot

@pytest.fixture
def main_model():
return MainModel()


@pytest.fixture
def experiments_model():
return FakeExperimentsModel()


@pytest.fixture
def training_model(main_model, experiments_model):
return TrainingModel(
main_model=main_model, experiments_model=experiments_model
)


@pytest.fixture
def viewer():
return FakeViewer()


@pytest.fixture
def training_view(qtbot: QtBot, main_model: MainModel, training_model: TrainingModel) -> TrainingView:
"""
Returns a PredictionView instance for testing.
"""
experimentsModel = FakeExperimentsModel()
return TrainingView(
main_model=main_model,
experiments_model=experimentsModel,
training_model=training_model,
viewer=FakeViewer(),
)


def test_set_patch_size(
training_view: TrainingView,
training_model: TrainingModel
) -> None:
"""
Tests that using the associated combo box properly sets the patch size field.
"""
for index, patch in enumerate(PatchSize):
# ACT
training_view._patch_size_combo_box.setCurrentIndex(index)

# ASSERT
True or training_model.get_patch_size() == patch


# def test_set_image_dimensions(
# qtbot: QtBot,
# model_selection_widget: ModelSelectionWidget,
# training_view: TrainingView,
# training_model: TrainingModel,
# ) -> None:
# """
Expand Down
20 changes: 15 additions & 5 deletions src/allencell_ml_segmenter/main/main_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
from allencell_ml_segmenter.main.experiments_model import ExperimentsModel
from allencell_ml_segmenter.main.main_model import MainModel
from allencell_ml_segmenter.prediction.view import PredictionView
from allencell_ml_segmenter.services.training_service import TrainingService
from allencell_ml_segmenter.training.model_selection_widget import (
ModelSelectionWidget,
)
from allencell_ml_segmenter.training.training_model import TrainingModel
from allencell_ml_segmenter.training.view import TrainingView


Expand All @@ -48,11 +50,11 @@ def __init__(self, viewer: napari.Viewer, config: CytoDlConfig = None):

if config is None:
config = CytoDlConfig(CYTO_DL_HOME_PATH, USER_EXPERIMENTS_PATH)
experiment_model = ExperimentsModel(config)
self._experiments_model = ExperimentsModel(config)

# Model selection which applies to all views
model_selection_widget: ModelSelectionWidget = ModelSelectionWidget(
experiment_model
self._experiments_model
)
model_selection_widget.setObjectName("modelSelection")
self.layout().addWidget(model_selection_widget, Qt.AlignTop)
Expand All @@ -68,12 +70,20 @@ def __init__(self, viewer: napari.Viewer, config: CytoDlConfig = None):
self._prediction_view: PredictionView = PredictionView(self._model)
self._initialize_view(self._prediction_view, "Prediction")

training_view: TrainingView = TrainingView(
self._training_model: TrainingModel = TrainingModel(
main_model=self._model, experiments_model=self._experiments_model
)
self._training_service: TrainingService = TrainingService(
training_model=self._training_model,
experiments_model=self._experiments_model,
)
self._training_view: TrainingView = TrainingView(
main_model=self._model,
viewer=self.viewer,
experiments_model=experiment_model,
experiments_model=self._experiments_model,
training_model=self._training_model,
)
self._initialize_view(training_view, "Training")
self._initialize_view(self._training_view, "Training")

self._curation_view: CurationWidget = CurationWidget(
self.viewer, self._model
Expand Down
9 changes: 2 additions & 7 deletions src/allencell_ml_segmenter/training/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def __init__(
self,
main_model: MainModel,
experiments_model: ExperimentsModel,
training_model: TrainingModel,
viewer: IViewer,
):
super().__init__()
Expand All @@ -52,13 +53,7 @@ def __init__(

self._main_model: MainModel = main_model
self._experiments_model: ExperimentsModel = experiments_model
self._training_model: TrainingModel = TrainingModel(
main_model, experiments_model
)
self._training_service: TrainingService = TrainingService(
training_model=self._training_model,
experiments_model=self._experiments_model,
)
self._training_model: TrainingModel = training_model

self.setLayout(QVBoxLayout())
self.layout().setContentsMargins(0, 0, 0, 0)
Expand Down

0 comments on commit 510d5d5

Please sign in to comment.