Ejemplo n.º 1
0
    def test_only_kwargs_with_default_arg_in_order(self):
        def fn(a, b=2, c='2345'):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=(),
                                      kwargs={'a': 1})

        assert kwargs == {'a': 1, 'b': 2, 'c': '2345'}
Ejemplo n.º 2
0
    def test_pep3102_ignore_args(self):
        def fn(a, b, *, d):  # noqa: E999
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=('A', 'B', 'C1', 'C2'),
                                      kwargs={'d': 'D'})

        assert kwargs == {'a': 'A', 'b': 'B', 'd': 'D'}
Ejemplo n.º 3
0
    def test_only_args_with_extra(self):
        def fn(a, b, *args):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=(1, 2, 3, 4, 5),
                                      kwargs={})

        assert kwargs == {'a': 1, 'b': 2, '*args': (3, 4, 5)}
Ejemplo n.º 4
0
    def test_only_args_with_default_arg(self):
        def fn(a, b=2, c=3):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=('A', ),
                                      kwargs={})

        assert kwargs == {'a': 'A', 'b': 2, 'c': 3}
Ejemplo n.º 5
0
    def test_only_args_with_extra_arg(self):
        def fn(a, *args):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=(1, 2),
                                      kwargs={})

        assert kwargs == {'a': 1, '*args': (2, )}
Ejemplo n.º 6
0
    def test_only_args(self):
        def fn(a, b):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=(1, 2),
                                      kwargs={})

        assert kwargs == {'a': 1, 'b': 2}
Ejemplo n.º 7
0
    def test_only_kwargs_with_extra_arg(self):
        def fn(a, *kwargs):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=(),
                                      kwargs={
                                          'a': 1,
                                          'b': 2
                                      })

        assert kwargs == {'a': 1, 'b': 2}
Ejemplo n.º 8
0
    def test_args_and_kwargs(self):
        def fn(a, b=2, c=3):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=('A', ),
                                      kwargs={
                                          'b': 'B',
                                          'c': 'C'
                                      })

        assert kwargs == {'a': 'A', 'b': 'B', 'c': 'C'}
Ejemplo n.º 9
0
    def test_args_and_kwargs_with_extra_and_default(self):
        def fn(a, b=2, c=3, *args, **kwargs):
            pass

        kwargs = merge_args_to_kwargs(argspec=get_arg_spec_py2_py3(fn),
                                      args=('A', 'B', 'C', 'D'),
                                      kwargs={'e': 'E'})

        assert kwargs == {
            'a': 'A',
            'b': 'B',
            'c': 'C',
            'e': 'E',
            '*args': ('D', )
        }