Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Czaki committed May 11, 2022
1 parent 5a41aa3 commit fb9eab3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions package/tests/test_PartSeg/test_common_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from io import BytesIO
from pathlib import Path
from typing import Callable, Optional
from unittest.mock import MagicMock

import numpy as np
import pytest
Expand Down Expand Up @@ -295,6 +296,26 @@ def test_running_start(self, qtbot, monkeypatch):
thr.finished_task()
assert start_list == [1, 1]

def test_setting_image(self, qtbot, monkeypatch, image):
algorithm_mock = MagicMock()
thread = segmentation_thread.SegmentationThread(algorithm_mock)
monkeypatch.setattr(thread, "isRunning", lambda: True)
assert thread._image is None
thread.set_image(image)
assert thread._image is image
algorithm_mock.set_image.assert_not_called()

assert thread._mask is None
thread.set_mask(image.get_channel(0))
assert thread._mask is not None
algorithm_mock.set_mask.assert_not_called()

thread.finished_task()
assert thread._image is None
assert thread._mask is None
algorithm_mock.set_image.assert_called_once()
algorithm_mock.set_mask.assert_called_once()


class ROIExtractionAlgorithmForTest(ROIExtractionAlgorithm):
def __init__(self, raise_=False, return_none=False):
Expand Down

0 comments on commit fb9eab3

Please sign in to comment.