Skip to content

Commit

Permalink
Merge pull request #357 from arcivanov/issue_356
Browse files Browse the repository at this point in the history
@dependents ignores customized task name
  • Loading branch information
arcivanov committed Apr 15, 2016
2 parents c1f740a + 49f03a5 commit c5d8a65
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/python/pybuilder/reactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def add_task_dependency(names, depends_on, optional):

for name in dir(project_module):
candidate = getattr(project_module, name)
name = normalize_candidate_name(candidate)

if getattr(candidate, TASK_ATTRIBUTE, None):
dependents = getattr(candidate, DEPENDENTS_ATTRIBUTE, None)
Expand All @@ -228,9 +229,9 @@ def add_task_dependency(names, depends_on, optional):
for d in dependents:
if isinstance(d, optional):
d = d()
add_task_dependency(d, candidate, True)
add_task_dependency(d, name, True)
else:
add_task_dependency(d, candidate, False)
add_task_dependency(d, name, False)

for name in dir(project_module):
candidate = getattr(project_module, name)
Expand Down
35 changes: 35 additions & 0 deletions src/unittest/python/reactor_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,41 @@ def task3():
self.execution_manager.register_late_task_dependencies.assert_has_calls(
[call({}), call({"task2": [TaskDependency(task3)]})])

def test_task_dependencies_with_post_definition_injections_custom_names(self):
import pybuilder.reactor

with patch("pybuilder.reactor.Task"):
@task
def task1():
pass

@task
@depends(task1)
def task2():
pass

@task("task_3")
@depends(task1)
@dependents(task2)
def task3():
pass

module1 = ModuleType("mock_module_one")
module1.task1 = task1
module1.task2 = task2

module2 = ModuleType("mock_module_two")
module2.task3 = task3

self.reactor.collect_tasks_and_actions_and_initializers(module1)
pybuilder.reactor.Task.assert_has_calls([call("task1", task1, [], ''),
call("task2", task2, [TaskDependency(task1)], '')])

self.reactor.collect_tasks_and_actions_and_initializers(module2)
pybuilder.reactor.Task.assert_has_calls([call("task_3", task3, [TaskDependency(task1)], '')])
self.execution_manager.register_late_task_dependencies.assert_has_calls(
[call({}), call({"task2": [TaskDependency("task_3")]})])

def test_should_collect_single_before_action(self):
@before("spam")
def action():
Expand Down

0 comments on commit c5d8a65

Please sign in to comment.