1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import pytest
 
from pandas.util._validators import validate_args
 
_fname = "func"
 
 
def test_bad_min_fname_arg_count():
    msg = "'max_fname_arg_count' must be non-negative"
 
    with pytest.raises(ValueError, match=msg):
        validate_args(_fname, (None,), -1, "foo")
 
 
def test_bad_arg_length_max_value_single():
    args = (None, None)
    compat_args = ("foo",)
 
    min_fname_arg_count = 0
    max_length = len(compat_args) + min_fname_arg_count
    actual_length = len(args) + min_fname_arg_count
    msg = (
        rf"{_fname}\(\) takes at most {max_length} "
        rf"argument \({actual_length} given\)"
    )
 
    with pytest.raises(TypeError, match=msg):
        validate_args(_fname, args, min_fname_arg_count, compat_args)
 
 
def test_bad_arg_length_max_value_multiple():
    args = (None, None)
    compat_args = {"foo": None}
 
    min_fname_arg_count = 2
    max_length = len(compat_args) + min_fname_arg_count
    actual_length = len(args) + min_fname_arg_count
    msg = (
        rf"{_fname}\(\) takes at most {max_length} "
        rf"arguments \({actual_length} given\)"
    )
 
    with pytest.raises(TypeError, match=msg):
        validate_args(_fname, args, min_fname_arg_count, compat_args)
 
 
@pytest.mark.parametrize("i", range(1, 3))
def test_not_all_defaults(i):
    bad_arg = "foo"
    msg = (
        f"the '{bad_arg}' parameter is not supported "
        rf"in the pandas implementation of {_fname}\(\)"
    )
 
    compat_args = {"foo": 2, "bar": -1, "baz": 3}
    arg_vals = (1, -1, 3)
 
    with pytest.raises(ValueError, match=msg):
        validate_args(_fname, arg_vals[:i], 2, compat_args)
 
 
def test_validation():
    # No exceptions should be raised.
    validate_args(_fname, (None,), 2, {"out": None})
 
    compat_args = {"axis": 1, "out": None}
    validate_args(_fname, (1, None), 2, compat_args)