From 72bf1b2c695edd57ebe5a4f1e883dd288b44b8b2 Mon Sep 17 00:00:00 2001 From: TimMonko <47310455+TimMonko@users.noreply.github.com> Date: Mon, 6 Jan 2025 22:38:55 -0600 Subject: [PATCH] directly call threaded function in test --- .../_tests/widgets/test_workflow_container.py | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/napari_ndev/_tests/widgets/test_workflow_container.py b/src/napari_ndev/_tests/widgets/test_workflow_container.py index f3b5972..1532aa9 100644 --- a/src/napari_ndev/_tests/widgets/test_workflow_container.py +++ b/src/napari_ndev/_tests/widgets/test_workflow_container.py @@ -66,7 +66,40 @@ def test_workflow_container_get_workflow_info(): assert container._tasks_select.value == list(container.workflow.leafs()) assert list(container._tasks_select.choices) == list(container.workflow._tasks.keys()) +def test_update_progress_bar(): + container = WorkflowContainer() + container._progress_bar.value = 0 + container._progress_bar.max = 10 + container._update_progress_bar(9) + assert container._progress_bar.value == 9 + +def test_batch_workflow_threaded(tmp_path, qtbot): + container = WorkflowContainer() + wf_path = pathlib.Path( + 'src/napari_ndev/_tests/resources/Workflow/workflows/' + 'cpu_workflow-2roots-2leafs.yaml' + ) + container.workflow_file.value = wf_path + + container.image_directory.value = pathlib.Path( + 'src/napari_ndev/_tests/resources/Workflow/Images' + ) + output_folder = tmp_path / 'Output' + output_folder.mkdir() + container.result_directory.value = output_folder + + container._batch_roots_container[0].value = 'membrane' + container._batch_roots_container[1].value = 'nuclei' + + worker = container._batch_workflow_threaded() + + with qtbot.waitSignal(worker.finished, timeout=10000): + pass + + assert output_folder.exists() + assert (output_folder / 'cells3d2ch.tiff').exists() + assert (output_folder / 'workflow.log.txt').exists() def test_batch_workflow_leaf_tasks(tmp_path, qtbot): container = WorkflowContainer() @@ -93,6 +126,8 @@ def test_batch_workflow_leaf_tasks(tmp_path, qtbot): with qtbot.waitSignal(container._batch_worker.finished, timeout=10000): pass + # confirm a value was yielded by batch_workflow + assert container._progress_bar.value == 1 # output folder does exist assert output_folder.exists() assert (output_folder / 'cells3d2ch.tiff').exists()