def test_meta_arg_default_disallowed(self): def py_callable(a, b, changed=None): pass task = Task('Fake', [(py_callable, ('a', 'b'))]) task.options = {} task.dep_changed = ['changed'] my_action = task.actions[0] pytest.raises(action.InvalidTask, my_action.execute)
def test_extra_kwarg_overwritten(self): got = [] def py_callable(a, b, **kwargs): got.append(a) got.append(b) got.append(kwargs['changed']) task = Task('Fake', [(py_callable, ('a', 'b'), {'changed': 'c'})]) task.options = {} task.dep_changed = ['changed'] my_action = task.actions[0] my_action.execute() assert got == ['a', 'b', 'c']
def test_extra_arg_overwritten(self): got = [] def py_callable(a, b, changed): got.append(a) got.append(b) got.append(changed) task = Task('Fake', [(py_callable, ('a', 'b', 'c'))]) task.dep_changed = ['changed'] task.options = {} my_action = task.actions[0] my_action.execute() assert got == ['a', 'b', 'c']
def test_mixed_args(self): got = [] def py_callable(a, b, changed): got.append(a) got.append(b) got.append(changed) task = Task('Fake', [(py_callable, ('a', 'b'))]) task.options = {} task.dep_changed = ['changed'] my_action = task.actions[0] my_action.execute() assert got == ['a', 'b', ['changed']]
def test_method(self): got = [] class CallMe(object): def xxx(self, a, b, changed): got.append(a) got.append(b) got.append(changed) task = Task('Fake', [(CallMe().xxx, ('a', 'b'))]) task.options = {} task.dep_changed = ['changed'] my_action = task.actions[0] my_action.execute() assert got == ['a', 'b', ['changed']]
def test_named_extra_args(self): got = [] def py_callable(targets, dependencies, changed, task): got.append(targets) got.append(dependencies) got.append(changed) got.append(task) task = Task('Fake', [py_callable], file_dep=['dependencies'], targets=['targets']) task.dep_changed = ['changed'] task.options = {} my_action = task.actions[0] my_action.execute() assert got == [['targets'], ['dependencies'], ['changed'], task]
def test_task_meta_reference(self): cmd = "%s %s/myecho.py" % (executable, TEST_PATH) cmd += " %(dependencies)s - %(changed)s - %(targets)s" dependencies = ["data/dependency1", "data/dependency2"] targets = ["data/target", "data/targetXXX"] task = Task('Fake', [cmd], dependencies, targets) task.dep_changed = ["data/dependency1"] task.options = {} my_action = task.actions[0] assert my_action.execute() is None got = my_action.out.split('-') assert task.file_dep == set(got[0].split()) assert task.dep_changed == got[1].split() assert targets == got[2].split()
def test_action_modifies_task_but_not_attrs(self): def py_callable(targets, dependencies, changed, task): targets.append('new_target') dependencies.append('new_dependency') changed.append('new_changed') task.file_dep.add('dep2') my_task = Task('Fake', [py_callable], file_dep=['dependencies'], targets=['targets']) my_task.dep_changed = ['changed'] my_task.options = {} my_action = my_task.actions[0] my_action.execute() assert my_task.file_dep == set(['dependencies', 'dep2']) assert my_task.targets == ['targets'] assert my_task.dep_changed == ['changed']