def test_format_arguments_case_repr_func_raises_error():
    """
    Test `format_arguments`.
    """

    # Create function
    def func(a):
        pass

    # Positional arguments
    args = [1]

    # Keyword arguments
    kwargs = {}

    # Create repr function that raises exception
    def repr_func(value):
        raise ValueError()

    # Format function arguments
    text = format_arguments(
        func=func,
        args=args,
        kwargs=kwargs,
        repr_func=repr_func,
    )

    # Check result text
    assert text == 'a=<?>'
def test_format_arguments_case_pos_kwd_dft_varkwd_args():
    """
    Test `format_arguments`.
    """

    # Create function
    def func(a, b, c=3, *args, **kwargs):
        pass

    # Positional arguments
    args = [1]

    # Keyword arguments
    kwargs = dict(b=2, x=100, y=200, z=300)

    # Format function arguments
    text = format_arguments(
        func=func,
        args=args,
        kwargs=kwargs,
        repr_func=repr,
    )

    # Check result text
    assert text == 'a=1, b=2, c=3, *args=[], **kwargs={x=100, y=200, z=300}'
def test_format_arguments_case_miss_args():
    """
    Test `format_arguments`.
    """

    # Create function
    def func(a, b):
        pass

    # Positional arguments
    args = [1]

    # Keyword arguments
    kwargs = {}

    # Format function arguments
    text = format_arguments(
        func=func,
        args=args,
        kwargs=kwargs,
        repr_func=repr,
    )

    # Check result text
    assert text == 'a=1'
def test_format_arguments_case_varkwd_args():
    """
    Test `format_arguments`.
    """

    # Create function
    def func(a, **kwargs):
        pass

    # Positional arguments
    args = [1]

    # Keyword arguments
    kwargs = dict(
        b=2,
        c=3,
    )

    # Format function arguments
    text = format_arguments(
        func=func,
        args=args,
        kwargs=kwargs,
        repr_func=repr,
    )

    # Check result text
    assert text == 'a=1, **kwargs={b=2, c=3}'
def test_format_arguments_case_filter_func():
    """
    Test `format_arguments`.
    """

    # Create class
    class CustomClass(object):

        # Create function with the first parameter name being `self`
        def func(self, a):
            pass

    # Positional arguments
    args = [0, 1]

    # Keyword arguments
    kwargs = {}

    # Format function arguments
    text = format_arguments(
        func=CustomClass.func,
        args=args,
        kwargs=kwargs,
        repr_func=repr,
    )

    # Check result text
    assert text == 'self=0, a=1'

    # Create inspect info filter function that removes `self` argument info
    def filter_func(info):
        """
        Inspect info filter function that removes `self` argument info.

        :param info: InspectInfo instance.

        :return: None.
        """
        # Get fixed argument infos dict
        fixed_arg_infos = info[InspectInfo.K_FIXED_ARG_INFOS]

        # If fixed argument infos dict is not empty
        if fixed_arg_infos:
            # Get the first fixed argument name
            first_arg_name = next(iter(fixed_arg_infos))

            # If the first fixed argument name is `self`
            if first_arg_name == 'self':
                # Remove `self` argument info
                del fixed_arg_infos['self']

    # Format function arguments
    text = format_arguments(
        func=CustomClass.func,
        args=args,
        kwargs=kwargs,
        repr_func=repr,
        filter_func=filter_func,
    )

    # Check result text
    assert text == 'a=1'