Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Add test_unit_aux_functions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tcompa committed Feb 16, 2024
1 parent 8bb1268 commit 97cb3c5
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 62 deletions.
62 changes: 0 additions & 62 deletions tests/test_apply_workflow.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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,
)
72 changes: 72 additions & 0 deletions tests/test_unit_aux_functions.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 97cb3c5

Please sign in to comment.