diff --git a/tests/test_apply_workflow.py b/tests/test_apply_workflow.py index a7e6444..c2662d0 100644 --- a/tests/test_apply_workflow.py +++ b/tests/test_apply_workflow.py @@ -1,9 +1,7 @@ -import pytest from devtools import debug from models import Dataset from models import Task from models import WorkflowTask -from runner import _validate_parallelization_list_valid from runner import apply_workflow from tests.tasks_for_tests import create_images_from_scratch @@ -41,63 +39,3 @@ def test_single_parallel_task_no_parallization_list(): ] dataset_out = apply_workflow(wf_task_list=task_list, dataset=dataset_in) debug(dataset_out.image_paths) - - -def test_unit_validate_parallelization_list(): - - # Missing path - PARALLELIZATION_LIST = [dict()] - CURRENT_IMAGE_PATHS = [] - with pytest.raises(ValueError): - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) - - # Path not in current image paths - PARALLELIZATION_LIST = [dict(path="asd")] - CURRENT_IMAGE_PATHS = [] - with pytest.raises(ValueError): - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) - - # Invalid buffer attributes - PARALLELIZATION_LIST = [dict(path="asd", buffer={})] - CURRENT_IMAGE_PATHS = ["asd"] - with pytest.raises(ValueError): - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) - - # Invalid `buffer`` attribute - PARALLELIZATION_LIST = [dict(path="asd", buffer={})] - CURRENT_IMAGE_PATHS = ["asd"] - with pytest.raises(ValueError): - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) - - # Invalid `root_dir` attribute - PARALLELIZATION_LIST = [dict(path="asd", root_dir="/something")] - CURRENT_IMAGE_PATHS = ["asd"] - with pytest.raises(ValueError): - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) - - # Valid call - PARALLELIZATION_LIST = [ - dict(path="asd", parameter=1), - dict(path="asd", parameter=2), - dict(path="asd", parameter=3), - ] - CURRENT_IMAGE_PATHS = ["asd"] - _validate_parallelization_list_valid( - parallelization_list=PARALLELIZATION_LIST, - current_image_paths=CURRENT_IMAGE_PATHS, - ) diff --git a/tests/test_unit_aux_functions.py b/tests/test_unit_aux_functions.py new file mode 100644 index 0000000..47e1362 --- /dev/null +++ b/tests/test_unit_aux_functions.py @@ -0,0 +1,72 @@ +import pytest +from images import _deduplicate_list_of_dicts +from runner import _validate_parallelization_list_valid + + +def test_validate_parallelization_list(): + + # Missing path + PARALLELIZATION_LIST = [dict()] + CURRENT_IMAGE_PATHS = [] + with pytest.raises(ValueError): + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + # Path not in current image paths + PARALLELIZATION_LIST = [dict(path="asd")] + CURRENT_IMAGE_PATHS = [] + with pytest.raises(ValueError): + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + # Invalid buffer attributes + PARALLELIZATION_LIST = [dict(path="asd", buffer={})] + CURRENT_IMAGE_PATHS = ["asd"] + with pytest.raises(ValueError): + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + # Invalid `buffer`` attribute + PARALLELIZATION_LIST = [dict(path="asd", buffer={})] + CURRENT_IMAGE_PATHS = ["asd"] + with pytest.raises(ValueError): + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + # Invalid `root_dir` attribute + PARALLELIZATION_LIST = [dict(path="asd", root_dir="/something")] + CURRENT_IMAGE_PATHS = ["asd"] + with pytest.raises(ValueError): + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + # Valid call + PARALLELIZATION_LIST = [ + dict(path="asd", parameter=1), + dict(path="asd", parameter=2), + dict(path="asd", parameter=3), + ] + CURRENT_IMAGE_PATHS = ["asd"] + _validate_parallelization_list_valid( + parallelization_list=PARALLELIZATION_LIST, + current_image_paths=CURRENT_IMAGE_PATHS, + ) + + +def test_deduplicate_list_of_dicts(): + old = [dict(a=1), dict(b=2)] + new = _deduplicate_list_of_dicts(old) + assert len(new) == 2 + old = [dict(a=1), dict(a=1), dict(b=2), dict(a=1)] + new = _deduplicate_list_of_dicts(old) + assert len(new) == 2