# Path: rebulk/loose.py
# def call(function, *args, **kwargs):
#     """
#     Call a function or constructor with given args and kwargs after removing args and kwargs that doesn't match
#     function or constructor signature
# 
#     :param function: Function or constructor to call
#     :type function: callable
#     :param args:
#     :type args:
#     :param kwargs:
#     :type kwargs:
#     :return: sale vakye as default function call
#     :rtype: object
#     """
#     func = constructor_args if isclass(function) else function_args
#     call_args, call_kwargs = func(function, *args, ignore_unused=True, **kwargs)  # @see #20
#     return function(*call_args, **call_kwargs)


from ..loose import call
# -*- coding: utf-8 -*-
# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition



def test_loose_function():

    def func(v1, v2, v3=3, v4=4):
        return v1 + v2 + v3 + v4

    assert call(func, 1, 2) == func(1, 2)
    assert call(func, 1, 2, 3, 5) == func(1, 2, 3, 5)
    assert call(func, 1, 2, v3=4, v4=5) == func(1, 2, v3=4, v4=5)
    assert call(func, 1, 2, 3, 4, 5) == func(1, 2, 3, 4)
    assert call(func, 1, 2, 3, 4, more=5) == func(1, 2, 3, 4)


def test_loose_varargs_function():
    def func(v1, v2, *args):
        return v1 + v2 + args[0] if len(args) > 0 else 3 + args[1] if len(args) > 1 else 4

    assert call(func, 1, 2) == func(1, 2)
    assert call(func, 1, 2, 3, 5) == func(1, 2, 3, 5)
    assert call(func, 1, 2, 3, 4, 5) == func(1, 2, 3, 4)


def test_loose_kwargs_function():
    def func(v1, v2, **kwargs):
        return v1 + v2 + kwargs.get('v3', 3) + kwargs.get('v4', 4)


# Path: rebulk/loose.py
# def call(function, *args, **kwargs):
#     """
#     Call a function or constructor with given args and kwargs after removing args and kwargs that doesn't match
#     function or constructor signature
# 
#     :param function: Function or constructor to call
#     :type function: callable
#     :param args:
#     :type args:
#     :param kwargs:
#     :type kwargs:
#     :return: sale vakye as default function call
#     :rtype: object
#     """
#     func = constructor_args if isclass(function) else function_args
#     call_args, call_kwargs = func(function, *args, ignore_unused=True, **kwargs)  # @see #20
#     return function(*call_args, **call_kwargs)


# Path: rebulk/test/test_loose.py
from ..loose import call

# -*- coding: utf-8 -*-
# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition



def test_loose_function():

    def func(v1, v2, v3=3, v4=4):
        return v1 + v2 + v3 + v4

    assert call(func, 1, 2) == func(1, 2)
    assert call(func, 1, 2, 3, 5) == func(1, 2, 3, 5)
    assert call(func, 1, 2, v3=4, v4=5) == func(1, 2, v3=4, v4=5)
    assert call(func, 1, 2, 3, 4, 5) == func(1, 2, 3, 4)
    assert call(func, 1, 2, 3, 4, more=5) == func(1, 2, 3, 4)


def test_loose_varargs_function():
    def func(v1, v2, *args):
        return v1 + v2 + args[0] if len(args) > 0 else 3 + args[1] if len(args) > 1 else 4

    assert call(func, 1, 2) == func(1, 2)
    assert call(func, 1, 2, 3, 5) == func(1, 2, 3, 5)
    assert call(func, 1, 2, 3, 4, 5) == func(1, 2, 3, 4)


def test_loose_kwargs_function():
    def func(v1, v2, **kwargs):
        return v1 + v2 + kwargs.get('v3', 3) + kwargs.get('v4', 4)


    assert call(func, v1=1, v2=2) == func(v1=1, v2=2)