def test_empty_image(self, capsys): thr = segmentation_thread.SegmentationThread( ROIExtractionAlgorithmForTest()) assert thr.get_info_text() == "text" thr.set_parameters(a=1) thr.run() assert capsys.readouterr().err.startswith("No image in")
def test_running_set_parameters(self, qtbot, monkeypatch): thr = segmentation_thread.SegmentationThread( ROIExtractionAlgorithmForTest()) thr.set_parameters(a=1) monkeypatch.setattr(thr, "isRunning", lambda: True) thr.set_parameters(a=2) assert thr.algorithm.new_parameters["a"] == 1 thr.finished_task() assert thr.algorithm.new_parameters["a"] == 2
def test_run_return_none(self, qtbot): algorithm = ROIExtractionAlgorithmForTest(return_none=True) thr = segmentation_thread.SegmentationThread(algorithm) image = Image(np.zeros((10, 10), dtype=np.uint8), image_spacing=(1, 1), axes_order="XY") algorithm.set_image(image) with qtbot.assertNotEmitted(thr.execution_done): thr.run()
def test_run(self, qtbot): algorithm = ROIExtractionAlgorithmForTest() thr = segmentation_thread.SegmentationThread(algorithm) image = Image(np.zeros((10, 10), dtype=np.uint8), image_spacing=(1, 1), axes_order="XY") algorithm.set_image(image) with qtbot.waitSignals([thr.execution_done, thr.progress_signal]): thr.run()
def test_run_exception(self, qtbot): algorithm = ROIExtractionAlgorithmForTest(raise_=True) thr = segmentation_thread.SegmentationThread(algorithm) image = Image(np.zeros((10, 10), dtype=np.uint8), image_spacing=(1, 1), axes_order="XY") algorithm.set_image(image) with qtbot.assertNotEmitted(thr.execution_done), qtbot.waitSignal( thr.exception_occurred): thr.run()
def test_running_start(self, qtbot, monkeypatch): start_list = [] monkeypatch.setattr(segmentation_thread.QThread, "start", lambda x, y: start_list.append(1)) thr = segmentation_thread.SegmentationThread( ROIExtractionAlgorithmForTest()) thr.start() assert start_list == [1] monkeypatch.setattr(thr, "isRunning", lambda: True) thr.start() assert start_list == [1] thr.finished_task() assert start_list == [1, 1]
def test_running_clean(self, qtbot, monkeypatch): clean_list = [] thr = segmentation_thread.SegmentationThread( ROIExtractionAlgorithmForTest()) monkeypatch.setattr(thr.algorithm, "clean", lambda: clean_list.append(1)) thr.clean() assert clean_list == [1] monkeypatch.setattr(thr, "isRunning", lambda: True) thr.clean() assert clean_list == [1] thr.finished_task() assert clean_list == [1, 1]