Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
yrkim98 committed Oct 18, 2023
1 parent 576bd98 commit 5edf5f3
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import List
from unittest.mock import Mock

import pytest
from qtpy.QtWidgets import QLabel, QComboBox, QPushButton
Expand All @@ -8,6 +9,7 @@
from allencell_ml_segmenter.core.event import Event
from allencell_ml_segmenter.curation.input_view import CurationInputView
from allencell_ml_segmenter.curation.curation_model import CurationModel
from allencell_ml_segmenter.curation.curation_service import CurationService


@pytest.fixture
Expand All @@ -17,7 +19,7 @@ def curation_model() -> CurationModel:

@pytest.fixture
def curation_input_view(curation_model: CurationModel, qtbot: QtBot) -> None:
return CurationInputView(curation_model)
return CurationInputView(curation_model, Mock(spec=CurationService))


def test_raw_channel_selected(
Expand Down
17 changes: 0 additions & 17 deletions src/allencell_ml_segmenter/_tests/curation/test_curation_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,23 +77,6 @@ def test_next_image(curation_main_view: CurationMainView) -> None:
== 2
)


def test_next_end_of_curation(curation_main_view: CurationMainView) -> None:
# Arrange
curation_main_view._update_curation_record = Mock()
curation_main_view.raw_images = [None, Path("path_raw")]
curation_main_view.seg1_images = [None, Path("path_seg1")]
curation_main_view.curation_index = 1

# Act
curation_main_view.next_image()

# Assert
assert (
curation_main_view._curation_service.write_curation_record.assert_called_once()
)


def test_increment_progress_bar(curation_main_view: CurationMainView) -> None:
# Arrange
initial_value: int = curation_main_view.progress_bar.value()
Expand Down
85 changes: 14 additions & 71 deletions src/allencell_ml_segmenter/_tests/curation/test_curation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ def curation_model():
def test_set_raw_directory(curation_model: CurationModel) -> None:
# Arrange
directory: Path = Path("fake_path")
with patch.object(CurationModel, "get_total_num_channels", return_value=3):
with patch.object(CurationModel, "dispatch") as dispatch_mock:
# Act
curation_model.set_raw_directory(directory)

# Assert
assert curation_model._raw_image_channel_count == 3
assert curation_model.get_raw_directory() == directory
assert dispatch_mock.called_with("ACTION_CURATION_RAW_SELECTED")
# Act
curation_model.set_raw_directory(directory)

# Assert
assert curation_model.get_raw_directory() == directory


def test_get_raw_directory(curation_model: CurationModel):
Expand All @@ -39,15 +36,11 @@ def test_get_raw_directory(curation_model: CurationModel):
def test_set_seg1_directory(curation_model: CurationModel) -> None:
# Arrange
directory: Path = Path("fake_path")
with patch.object(CurationModel, "get_total_num_channels", return_value=4):
with patch.object(CurationModel, "dispatch") as dispatch_mock:
# Act
curation_model.set_seg1_directory(directory)
# Act
curation_model.set_seg1_directory(directory)

# Assert
assert curation_model._seg1_image_channel_count == 4
assert curation_model.get_seg1_directory() == directory
assert dispatch_mock.called_with("ACTION_CURATION_SEG1_SELECTED")
# Assert
assert curation_model.get_seg1_directory() == directory


def test_get_seg1_directory():
Expand All @@ -62,15 +55,12 @@ def test_get_seg1_directory():
def test_set_seg2_directory(curation_model: CurationModel):
# Arrange
directory: Path = Path("fake_path")
with patch.object(CurationModel, "get_total_num_channels", return_value=5):
with patch.object(CurationModel, "dispatch") as dispatch_mock:
# Act
curation_model.set_seg2_directory(directory)

# Assert
assert curation_model._seg2_image_channel_count == 5
assert curation_model.get_seg2_directory() == directory
assert dispatch_mock.called_with("ACTION_CURATION_SEG2_SELECTED")
# Act
curation_model.set_seg2_directory(directory)

# Assert
assert curation_model.get_seg2_directory() == directory


def test_get_seg2_directory(curation_model: CurationModel):
Expand Down Expand Up @@ -127,51 +117,4 @@ def test_set_view(curation_model: CurationModel):
)


def test_get_total_num_channels_raw(curation_model: CurationModel):
# Arrange
directory: Path = Path("/path/to/raw_directory")
with patch.object(CurationModel, "get_total_num_channels", return_value=3):
curation_model.set_raw_directory(directory)

# Act
num_channels = curation_model.get_total_num_channels_raw()

# Assert
assert num_channels == 3


def test_get_total_num_channels_seg1(curation_model: CurationModel):
# Arrange
directory: Path = Path("/path/to/seg1_directory")
with patch.object(CurationModel, "get_total_num_channels", return_value=3):
curation_model.set_seg1_directory(directory)

# Act
num_channels: int = curation_model.get_total_num_channels_seg1()

# Assert
assert num_channels == 3


def test_get_total_num_channels_seg2(curation_model: CurationModel):
# Arrange
directory: Path = Path("/path/to/seg2_directory")
with patch.object(CurationModel, "get_total_num_channels", return_value=4):
curation_model.set_seg2_directory(directory)

# Act
num_channels = curation_model.get_total_num_channels_seg2()

# Assert
assert num_channels == 4


def test_get_total_num_channels(curation_model: CurationModel):
# Arrange
directory = Path("/path/to/raw_directory")
with patch.object(CurationModel, "get_total_num_channels", return_value=6):
# Act
num_channels = curation_model.get_total_num_channels(directory)

# Assert
assert num_channels == 6
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from allencell_ml_segmenter._tests.fakes.fake_experiments_model import (
FakeExperimentsModel,
)
from allencell_ml_segmenter.curation.curation_service import CurationService
from allencell_ml_segmenter.main.experiments_model import ExperimentsModel
from allencell_ml_segmenter.main.main_model import MainModel
from allencell_ml_segmenter.curation.curation_model import CurationModel
Expand Down Expand Up @@ -49,7 +50,7 @@ def test_initialize_views(
curation_model: CurationModel, curation_widget: CurationWidget
):
# Arrange
input_view: CurationInputView = CurationInputView(curation_model)
input_view: CurationInputView = CurationInputView(curation_model, Mock(spec=CurationService))

# Act
curation_widget.initialize_view(input_view)
Expand All @@ -65,7 +66,7 @@ def test_set_view(
curation_model: CurationModel, curation_widget: CurationWidget
):
# Arrange
input_view: CurationInputView = CurationInputView(curation_model)
input_view: CurationInputView = CurationInputView(curation_model, Mock(spec=CurationService))
curation_widget.initialize_view(input_view)

# Act
Expand Down
11 changes: 0 additions & 11 deletions src/allencell_ml_segmenter/curation/curation_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,3 @@ def set_total_num_channels_seg1(self, channels: int) -> int:

def set_total_num_channels_seg2(self, channels: int) -> int:
self._seg2_image_channel_count = channels

def get_total_num_channels(self, path: Path) -> int:
"""
Determine total number of channels for image in a set folder
"""
# we expect user to have the same number of channels for all images in their folders
# and that only images are stored in those folders
first_image: Path = path.iterdir().__next__()
img: AICSImage = AICSImage(str(first_image.resolve()))
# return num channel
return img.dims.C

0 comments on commit 5edf5f3

Please sign in to comment.