Skip to content

Commit

Permalink
change tests to use service for curation_main
Browse files Browse the repository at this point in the history
  • Loading branch information
yrkim98 committed Oct 18, 2023
1 parent 2524c82 commit 64249a6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
44 changes: 43 additions & 1 deletion src/allencell_ml_segmenter/_tests/curation/test_curation_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from allencell_ml_segmenter.curation.curation_model import CurationModel
from allencell_ml_segmenter.curation.curation_service import CurationService

import napari
from unittest.mock import Mock
from pytestqt.qtbot import QtBot
from pathlib import Path
Expand All @@ -19,6 +18,21 @@ def curation_main_view(qtbot: QtBot) -> CurationMainView:
curation_service: Mock = Mock(spec=CurationService)
return CurationMainView(curation_model, experiments_model, curation_service)

def test_curation_setup(curation_main_view):
# Arrange
curation_main_view._curation_service.get_raw_images_list = Mock(return_value=[Path("path_raw")])
curation_main_view._curation_service.get_seg1_images_list = Mock(return_value=[Path("path_seg1")])
curation_main_view.init_progress_bar = Mock()

# Act
curation_main_view.curation_setup()

# Assert
curation_main_view.init_progress_bar.assert_called_once()
curation_main_view._curation_service.remove_all_images_from_viewer_layers.assert_called_once()
curation_main_view._curation_service.add_image_to_viewer.called_once_with(["path_raw"], f"[raw] path_raw")
curation_main_view._curation_service.add_image_to_viewer.called_once_with(["path_seg1"], f"[raw] path_seg1")


def test_curation_main_view_init(curation_main_view: CurationMainView) -> None:
# Arrange, Act, Assert
Expand All @@ -32,6 +46,34 @@ def test_init_progress_bar(curation_main_view: CurationMainView) -> None:
# Assert
assert curation_main_view.progress_bar.value() == 1

def test_next_image(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")]
assert curation_main_view.curation_index == 0

# Act
curation_main_view.next_image()

# Assert
curation_main_view._update_curation_record.assert_called_once()
assert curation_main_view.curation_index == 1
curation_main_view._curation_service.remove_all_images_from_viewer_layers.assert_called_once()
assert curation_main_view._curation_service.add_image_to_viewer.call_count == 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
Expand Down
6 changes: 0 additions & 6 deletions src/allencell_ml_segmenter/curation/main_view.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import csv
from pathlib import Path
from typing import List
import napari
from qtpy.QtCore import Qt
from qtpy.QtWidgets import (
QVBoxLayout,
Expand All @@ -13,8 +11,6 @@
QProgressBar,
QRadioButton,
)
from aicsimageio import AICSImage

from allencell_ml_segmenter._style import Style
from allencell_ml_segmenter.core.view import View
from allencell_ml_segmenter.curation.curation_data_class import CurationRecord
Expand All @@ -24,8 +20,6 @@
from allencell_ml_segmenter.widgets.label_with_hint_widget import LabelWithHint

from napari.utils.notifications import show_info
from napari.layers.shapes.shapes import Shapes
import shutil


class CurationMainView(View):
Expand Down

0 comments on commit 64249a6

Please sign in to comment.