Exemple #1
0
 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)
Exemple #2
0
 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)
Exemple #3
0
 def test_callable_invalid(self):
     def get_cmd(blabla): pass
     task = Task('Fake', [action.CmdAction(get_cmd)])
     task.options = {'opt1':'3'}
     my_action = task.actions[0]
     got = my_action.execute()
     assert isinstance(got, TaskError)
Exemple #4
0
 def test_callable_invalid(self):
     def get_cmd(blabla): pass
     task = Task('Fake', [action.CmdAction(get_cmd)])
     task.options = {'opt1':'3'}
     my_action = task.actions[0]
     got = my_action.execute()
     assert isinstance(got, TaskError)
Exemple #5
0
 def test_no_extra_args(self):
     # no error trying to inject values
     def py_callable():
         return True
     task = Task('Fake', [py_callable], file_dep=['dependencies'])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
Exemple #6
0
 def test_no_extra_args(self):
     # no error trying to inject values
     def py_callable():
         return True
     task = Task('Fake', [py_callable], file_dep=['dependencies'])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
Exemple #7
0
 def test_option_default_allowed(self):
     got = []
     def py_callable(opt2='ABC'):
         got.append(opt2)
     task = Task('Fake', [py_callable])
     task.options = {'opt2':'123'}
     my_action = task.actions[0]
     my_action.execute()
     assert ['123'] == got, repr(got)
Exemple #8
0
 def test_option_default_allowed(self):
     got = []
     def py_callable(opt2='ABC'):
         got.append(opt2)
     task = Task('Fake', [py_callable])
     task.options = {'opt2':'123'}
     my_action = task.actions[0]
     my_action.execute()
     assert ['123'] == got, repr(got)
Exemple #9
0
 def test_task_options(self):
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(opt1)s - %(opt2)s"
     task = Task('Fake', [cmd])
     task.options = {'opt1':'3', 'opt2':'abc def'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "3 - abc def" == got
Exemple #10
0
 def test_task_options(self):
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(opt1)s - %(opt2)s"
     task = Task('Fake', [cmd])
     task.options = {'opt1':'3', 'opt2':'abc def'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "3 - abc def" == got
Exemple #11
0
 def test_both(self, monkeypatch):
     monkeypatch.setattr(action.CmdAction, 'STRING_FORMAT', 'both')
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " {dependencies} - %(opt1)s"
     task = Task('Fake', [cmd], ['data/dependency1'])
     task.options = {'opt1':'abc'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "data/dependency1 - abc" == got
Exemple #12
0
 def test_callable_return_command_str(self):
     def get_cmd(opt1, opt2):
         cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
         return cmd + " %s - %s" % (opt1, opt2)
     task = Task('Fake', [action.CmdAction(get_cmd)])
     task.options = {'opt1':'3', 'opt2':'abc def'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "3 - abc def" == got, repr(got)
Exemple #13
0
 def test_task_pos_arg(self):
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(pos)s"
     task = Task('Fake', [cmd], pos_arg='pos')
     task.options = {}
     task.pos_arg_val = ['hi', 'there']
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "hi there" == got
Exemple #14
0
 def test_task_options(self):
     got = []
     def py_callable(opt1, opt3):
         got.append(opt1)
         got.append(opt3)
     task = Task('Fake', [py_callable])
     task.options = {'opt1':'1', 'opt2':'abc def', 'opt3':3}
     my_action = task.actions[0]
     my_action.execute()
     assert ['1',3] == got, repr(got)
Exemple #15
0
 def test_task_pos_arg(self):
     got = []
     def py_callable(pos):
         got.append(pos)
     task = Task('Fake', [py_callable], pos_arg='pos')
     task.options = {}
     task.pos_arg_val = ['hi', 'there']
     my_action = task.actions[0]
     my_action.execute()
     assert [['hi', 'there']] == got, repr(got)
Exemple #16
0
 def test_task_options(self):
     got = []
     def py_callable(opt1, opt3):
         got.append(opt1)
         got.append(opt3)
     task = Task('Fake', [py_callable])
     task.options = {'opt1':'1', 'opt2':'abc def', 'opt3':3}
     my_action = task.actions[0]
     my_action.execute()
     assert ['1',3] == got, repr(got)
Exemple #17
0
 def test_both(self, monkeypatch):
     monkeypatch.setattr(action.CmdAction, 'STRING_FORMAT', 'both')
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " {dependencies} - %(opt1)s"
     task = Task('Fake', [cmd], ['data/dependency1'])
     task.options = {'opt1':'abc'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "data/dependency1 - abc" == got
Exemple #18
0
 def test_callable_return_command_str(self):
     def get_cmd(opt1, opt2):
         cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
         return cmd + " %s - %s" % (opt1, opt2)
     task = Task('Fake', [action.CmdAction(get_cmd)])
     task.options = {'opt1':'3', 'opt2':'abc def'}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "3 - abc def" == got, repr(got)
Exemple #19
0
 def test_task_pos_arg(self):
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(pos)s"
     task = Task('Fake', [cmd], pos_arg='pos')
     task.options = {}
     task.pos_arg_val = ['hi', 'there']
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "hi there" == got
Exemple #20
0
 def test_task_pos_arg(self):
     got = []
     def py_callable(pos):
         got.append(pos)
     task = Task('Fake', [py_callable], pos_arg='pos')
     task.options = {}
     task.pos_arg_val = ['hi', 'there']
     my_action = task.actions[0]
     my_action.execute()
     assert [['hi', 'there']] == got, repr(got)
Exemple #21
0
 def test_keyword_extra_args(self):
     got = []
     def py_callable(arg=None, **kwargs):
         got.append(kwargs)
     my_task = Task('Fake', [(py_callable, (), {'b': 4})],
                    file_dep=['dependencies'])
     my_task.options = {'foo': 'bar'}
     my_action = my_task.actions[0]
     my_action.execute()
     # meta args do not leak into kwargs
     assert got == [{'foo': 'bar', 'b': 4}]
Exemple #22
0
 def test_task_pos_arg_None(self):
     # pos_arg_val is None when the task is not specified from
     # command line but executed because it is a task_dep
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(pos)s"
     task = Task('Fake', [cmd], pos_arg='pos')
     task.options = {}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "" == got
Exemple #23
0
 def test_keyword_extra_args(self):
     got = []
     def py_callable(arg=None, **kwargs):
         got.append(kwargs)
     my_task = Task('Fake', [(py_callable, (), {'b': 4})],
                    file_dep=['dependencies'])
     my_task.options = {'foo': 'bar'}
     my_action = my_task.actions[0]
     my_action.execute()
     # meta args do not leak into kwargs
     assert got == [{'foo': 'bar', 'b': 4}]
Exemple #24
0
 def test_task_pos_arg_None(self):
     # pos_arg_val is None when the task is not specified from
     # command line but executed because it is a task_dep
     cmd = "%s %s/myecho.py" % (executable, TEST_PATH)
     cmd += " %(pos)s"
     task = Task('Fake', [cmd], pos_arg='pos')
     task.options = {}
     my_action = task.actions[0]
     assert my_action.execute() is None
     got = my_action.out.strip()
     assert "" == got
Exemple #25
0
 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']]
Exemple #26
0
 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']
Exemple #27
0
 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']]
Exemple #28
0
 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']
Exemple #29
0
 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']
Exemple #30
0
 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']
Exemple #31
0
 def test_kwonlyargs_minimal(self):
     got = []
     scope = {'got': got}
     exec(textwrap.dedent('''
         def py_callable(*args, kwonly=None):
             got.append(args)
             got.append(kwonly)
     '''), scope)
     task = Task('Fake', [(scope['py_callable'], (1, 2, 3), {'kwonly': 4})])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
     assert [(1, 2, 3), 4] == got, repr(got)
Exemple #32
0
 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']]
Exemple #33
0
 def test_kwonlyargs_minimal(self):
     got = []
     scope = {'got': got}
     exec(textwrap.dedent('''
         def py_callable(*args, kwonly=None):
             got.append(args)
             got.append(kwonly)
     '''), scope)
     task = Task('Fake', [(scope['py_callable'], (1, 2, 3), {'kwonly': 4})])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
     assert [(1, 2, 3), 4] == got, repr(got)
Exemple #34
0
 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']]
Exemple #35
0
    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()
Exemple #36
0
 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]
Exemple #37
0
 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]
Exemple #38
0
    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()
Exemple #39
0
    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']
Exemple #40
0
 def test_kwonlyargs_full(self):
     got = []
     scope = {'got': got}
     exec(textwrap.dedent('''
         def py_callable(pos, *args, kwonly=None, **kwargs):
             got.append(pos)
             got.append(args)
             got.append(kwonly)
             got.append(kwargs['foo'])
     '''), scope)
     task = Task('Fake', [
         (scope['py_callable'], [1,2,3], {'kwonly': 4, 'foo': 5})])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
     assert [1, (2, 3), 4, 5] == got, repr(got)
Exemple #41
0
 def test_kwonlyargs_full(self):
     got = []
     scope = {'got': got}
     exec(textwrap.dedent('''
         def py_callable(pos, *args, kwonly=None, **kwargs):
             got.append(pos)
             got.append(args)
             got.append(kwonly)
             got.append(kwargs['foo'])
     '''), scope)
     task = Task('Fake', [
         (scope['py_callable'], [1,2,3], {'kwonly': 4, 'foo': 5})])
     task.options = {}
     my_action = task.actions[0]
     my_action.execute()
     assert [1, (2, 3), 4, 5] == got, repr(got)
Exemple #42
0
    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']