Skip to content

Commit

Permalink
Fixed issue #46
Browse files Browse the repository at this point in the history
  • Loading branch information
nonlosao committed May 5, 2023
1 parent 31d096c commit 0e16de1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 11 additions & 2 deletions author/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,17 @@ def __init__(self, arguments, is_handle_task=True, wait_for_task=None, *args, **
_LOG.debug("Handletask {}. Adding simple dependency...".format(self))
self._add_command_tasks(*args, **kwargs)
elif self.elements_id and self.per_element and self._is_expected_iterable(getattr(self.elements, "processed", None)):
for element in self.elements.processed:
element = ArgumentValue(self.elements.initial, element)
elements = []
if isinstance(self.elements.processed, dict):
for key_value in self.elements.processed.items():
element = ArgumentValue(self.elements.initial, key_value)
elements.append(element)
else:
for element in self.elements.processed:
element = ArgumentValue(self.elements.initial, element)
elements.append(element)

for element in elements:
self._add_required_tasks(self.required_tasks, self, elements=element, *args, **kwargs)
else:
self._add_required_tasks(self.required_tasks, self, elements=self.elements, *args, **kwargs)
Expand Down
20 changes: 20 additions & 0 deletions tests/author/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
)

from jobtronaut.author import (
Arguments,
ArgumentValue,
Task,
TaskWithOverrides
Expand Down Expand Up @@ -296,6 +297,25 @@ def test_add_command_tasks(self, mock_per_element):
_task = TaskFixture(TASK_FIXTURE_ARGUMENTS)
self.assertEqual(len(_task.arguments[_task.elements_id].initial), len(_task.subtasks))

# lets check if the PER_ELEMENT resolved contain the proper element/ArgumentValue
index = 0
for handle_task in _task.subtasks:
for command_task in handle_task.subtasks:
self.assertEqual(command_task.elements.processed, _task.arguments[_task.elements_id].initial[index])
index += 1

TASK_FIXTURE_ARGUMENTS["test_argument"] = {"a": 1, "b": 2}
_task = TaskFixture(TASK_FIXTURE_ARGUMENTS)
all_items_sorted = sorted(list(TASK_FIXTURE_ARGUMENTS["test_argument"].items()), key=lambda item: item[0])
all_command_tasks = []
for handle_task in _task.subtasks:
for command_task in handle_task.subtasks:
all_command_tasks.append(command_task)
all_elements_sorted = sorted([_.elements.processed for _ in all_command_tasks], key=lambda item: item[0])

self.assertEqual(all_elements_sorted, all_items_sorted)


@patch.object(TaskFixture, "view", create=True, new=lambda x: x.cmd()[-1])
@patch.object(TaskFixture, "cmd", create=True, new=lambda x: ["/some/executable", "test"])
@patch("jobtronaut.author.task.EXECUTABLE_RESOLVER", new=lambda x: "/bin/echo")
Expand Down

0 comments on commit 0e16de1

Please sign in to comment.