Esempio n. 1
0
    def test_mixed_args(self, task_depchanged):
        got = []

        def py_callable(a, b, changed):
            got.append(a)
            got.append(b)
            got.append(changed)

        my_action = action.PythonAction(py_callable, ('a', 'b'),
                                        task=task_depchanged)
        my_action.execute()
        assert got == ['a', 'b', ['changed']]
Esempio n. 2
0
    def test_extra_arg_overwritten(self, task_depchanged):
        got = []

        def py_callable(a, b, changed):
            got.append(a)
            got.append(b)
            got.append(changed)

        my_action = action.PythonAction(py_callable, ('a', 'b', 'c'),
                                        task=task_depchanged)
        my_action.execute()
        assert got == ['a', 'b', 'c']
Esempio n. 3
0
    def test_extra_kwarg_overwritten(self, task_depchanged):
        got = []

        def py_callable(a, b, **kwargs):
            got.append(a)
            got.append(b)
            got.append(kwargs['changed'])

        my_action = action.PythonAction(py_callable, ('a', 'b'),
                                        {'changed': 'c'}, task_depchanged)
        my_action.execute()
        assert got == ['a', 'b', 'c']
Esempio n. 4
0
    def test_callable_obj(self, task_depchanged):
        got = []

        class CallMe(object):
            def __call__(self, a, b, changed):
                got.append(a)
                got.append(b)
                got.append(changed)

        my_action = action.PythonAction(CallMe(), ('a', 'b'),
                                        task=task_depchanged)
        my_action.execute()
        assert got == ['a', 'b', ['changed']]
Esempio n. 5
0
    def test_init(self):
        # default values
        action1 = action.PythonAction(self._func_par)
        assert action1.args == []
        assert action1.kwargs == {}

        # not a callable
        pytest.raises(action.InvalidTask, action.PythonAction, "abc")
        # args not a list
        pytest.raises(action.InvalidTask, action.PythonAction, self._func_par, "c")
        # kwargs not a list
        pytest.raises(action.InvalidTask, action.PythonAction,
                      self._func_par, None, "a")
Esempio n. 6
0
    def test_named_extra_args(self, task_depchanged):
        got = []

        def py_callable(targets, dependencies, changed, task):
            got.append(targets)
            got.append(dependencies)
            got.append(changed)
            got.append(task)

        my_action = action.PythonAction(py_callable, task=task_depchanged)
        my_action.execute()
        assert got == [['targets'], ['dependencies'], ['changed'],
                       task_depchanged]
Esempio n. 7
0
    def test_action_modifies_task_attributes(self, task_depchanged):
        def py_callable(targets, dependencies, changed, task):
            targets.append('new_target')
            dependencies.append('new_dependency')
            changed.append('new_changed')
        my_action = action.PythonAction(py_callable, task=task_depchanged)
        my_action.execute()

        assert task_depchanged.file_dep == ['dependencies', 'new_dependency']

        assert task_depchanged.targets == ['targets', 'new_target']

        assert task_depchanged.dep_changed == ['changed', 'new_changed']
Esempio n. 8
0
 def test_kwonlyargs_minimal(self, task_depchanged):
     got = []
     scope = {'got': got}
     exec(textwrap.dedent('''
         def py_callable(*args, kwonly=None):
             got.append(args)
             got.append(kwonly)
     '''), scope)
     my_action = action.PythonAction(scope['py_callable'],
                                     (1, 2, 3), {'kwonly': 4},
                                     task=task_depchanged)
     my_action.execute()
     assert [(1, 2, 3), 4] == got, repr(got)
Esempio n. 9
0
    def test_method(self, task_depchanged):
        got = []

        class CallMe(object):
            def xxx(self, a, b, changed):
                got.append(a)
                got.append(b)
                got.append(changed)

        my_action = action.PythonAction(CallMe().xxx, ('a', 'b'),
                                        task=task_depchanged)
        my_action.execute()
        assert got == ['a', 'b', ['changed']]
Esempio n. 10
0
 def test_kwonlyargs_full(self, task_depchanged):
     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)
     my_action = action.PythonAction(scope['py_callable'],
                                     [1,2,3], {'kwonly': 4, 'foo': 5},
                                     task=task_depchanged)
     my_action.execute()
     assert [1, (2, 3), 4, 5] == got, repr(got)
Esempio n. 11
0
    def test_task_options(self):
        got = []

        def py_callable(opt1, opt3):
            got.append(opt1)
            got.append(opt3)

        task = FakeTask([], [], [], {
            'opt1': '1',
            'opt2': 'abc def',
            'opt3': 3
        })
        my_action = action.PythonAction(py_callable, task=task)
        my_action.execute()
        assert ['1', 3] == got, repr(got)
Esempio n. 12
0
 def test_functionParametersArgs(self):
     my_action = action.PythonAction(self._func_par,args=(2,2,25))
     my_action.execute()
Esempio n. 13
0
 def test_functionParametersKwargs(self):
     my_action = action.PythonAction(self._func_par,
                           kwargs={'par1':2,'par2':2,'par3':25})
     my_action.execute()
Esempio n. 14
0
 def test_fail_bool(self):
     def fail_sample():return False
     my_action = action.PythonAction(fail_sample)
     got = my_action.execute()
     assert isinstance(got, TaskFailed)
Esempio n. 15
0
    def test_no_extra_args(self, task_depchanged):
        def py_callable():
            return True

        my_action = action.PythonAction(py_callable, task=task_depchanged)
        my_action.execute()
Esempio n. 16
0
 def test_functionParameters(self):
     my_action = action.PythonAction(self._func_par,args=(2,2),
                                kwargs={'par3':25})
     my_action.execute()
Esempio n. 17
0
 def test_captureStdout(self):
     my_action = action.PythonAction(self.write_stdout)
     my_action.execute()
     assert "this is stdout S\n" == my_action.out, repr(my_action.out)
Esempio n. 18
0
 def test_values(self):
     def vvv(): return {'x': 5, 'y':10}
     my_action = action.PythonAction(vvv)
     my_action.execute()
     assert {'x': 5, 'y':10} == my_action.values
Esempio n. 19
0
 def test_result(self):
     def vvv(): return "my value"
     my_action = action.PythonAction(vvv)
     my_action.execute()
     assert "my value" == my_action.result
Esempio n. 20
0
 def test_str(self):
     def str_sample(): return True
     my_action = action.PythonAction(str_sample)
     assert "Python: function" in str(my_action)
     assert "str_sample" in str(my_action)
Esempio n. 21
0
 def test_functionParametersFail(self):
     my_action = action.PythonAction(self._func_par, args=(2,3),
                                kwargs={'par3':25})
     got = my_action.execute()
     assert isinstance(got, TaskFailed)
Esempio n. 22
0
 def test_success_dict(self):
     def success_sample():return {}
     my_action = action.PythonAction(success_sample)
     # nothing raised it was successful
     my_action.execute()
Esempio n. 23
0
 def test_repr(self):
     def repr_sample(): return True
     my_action = action.PythonAction(repr_sample)
     assert  "<PythonAction: '%s'>" % repr(repr_sample) == repr(my_action)
Esempio n. 24
0
 def test_error_object(self):
     # anthing but None, bool, string or dict
     def error_sample(): return object()
     my_action = action.PythonAction(error_sample)
     got = my_action.execute()
     assert isinstance(got, TaskError)
Esempio n. 25
0
 def test_result_dict(self):
     def vvv(): return {'xxx': "my value"}
     my_action = action.PythonAction(vvv)
     my_action.execute()
     assert {'xxx': "my value"} == my_action.result
Esempio n. 26
0
 def test_error_taskerror(self):
     def error_sample(): return TaskError("so sad")
     ye_olde_action = action.PythonAction(error_sample)
     ret = ye_olde_action.execute()
     assert str(ret).endswith("so sad\n")
Esempio n. 27
0
 def test_captureStderr(self):
     my_action = action.PythonAction(self.write_stderr)
     my_action.execute()
     assert "this is stderr S\n" == my_action.err, repr(my_action.err)
Esempio n. 28
0
 def test_error_exception(self):
     def error_sample(): raise Exception("asdf")
     my_action = action.PythonAction(error_sample)
     got = my_action.execute()
     assert isinstance(got, TaskError)
Esempio n. 29
0
 def test_noCaptureStdout(self, capsys):
     my_action = action.PythonAction(self.write_stdout)
     my_action.execute(out=sys.stdout)
     got = capsys.readouterr()[0]
     assert "this is stdout S\n" == got, repr(got)
Esempio n. 30
0
 def test_meta_arg_default_disallowed(self, task_depchanged):
     def py_callable(a, b, changed=None): pass
     my_action = action.PythonAction(py_callable, ('a', 'b'),
                                     task=task_depchanged)
     pytest.raises(action.InvalidTask, my_action.execute)