示例#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)
示例#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)
示例#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)
示例#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)
示例#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()
示例#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()
示例#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)
示例#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)
示例#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
示例#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
示例#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
示例#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)
示例#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
示例#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)
示例#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)
示例#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)
示例#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
示例#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)
示例#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
示例#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)
示例#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}]
示例#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
示例#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}]
示例#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
示例#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']]
示例#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']
示例#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']]
示例#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']
示例#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']
示例#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']
示例#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)
示例#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']]
示例#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)
示例#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']]
示例#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()
示例#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]
示例#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]
示例#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()
示例#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']
示例#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)
示例#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)
示例#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']