Exemple #1
0
    def __call__(
        self,
        args,
        kwargs,
        fname=None,
        max_fname_arg_count=None,
        method: Optional[str] = None,
    ) -> None:
        if args or kwargs:
            fname = self.fname if fname is None else fname
            max_fname_arg_count = (
                self.max_fname_arg_count
                if max_fname_arg_count is None
                else max_fname_arg_count
            )
            method = self.method if method is None else method

            if method == "args":
                validate_args(fname, args, max_fname_arg_count, self.defaults)
            elif method == "kwargs":
                validate_kwargs(fname, kwargs, self.defaults)
            elif method == "both":
                validate_args_and_kwargs(
                    fname, args, kwargs, max_fname_arg_count, self.defaults
                )
            else:
                raise ValueError(f"invalid validation method '{method}'")
def test_validation():
    # No exceptions should be raised.
    validate_args(_fname, (None,), 2, dict(out=None))

    compat_args = OrderedDict()
    compat_args["axis"] = 1
    compat_args["out"] = None

    validate_args(_fname, (1, None), 2, compat_args)
    def test_validation(self):
        # No exceptions should be thrown
        validate_args(self.fname, (None,), 2, dict(out=None))

        compat_args = OrderedDict()
        compat_args['axis'] = 1
        compat_args['out'] = None

        validate_args(self.fname, (1, None), 2, compat_args)
Exemple #4
0
    def test_validation(self):
        # No exceptions should be thrown
        validate_args(self.fname, (None,), 2, dict(out=None))

        compat_args = OrderedDict()
        compat_args['axis'] = 1
        compat_args['out'] = None

        validate_args(self.fname, (1, None), 2, compat_args)
Exemple #5
0
def test_validation():
    # No exceptions should be raised.
    validate_args(_fname, (None, ), 2, dict(out=None))

    compat_args = OrderedDict()
    compat_args["axis"] = 1
    compat_args["out"] = None

    validate_args(_fname, (1, None), 2, compat_args)
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_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)
Exemple #8
0
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 = (fr"{_fname}\(\) takes at most {max_length} "
           fr"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 = dict(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 = (r"{fname}\(\) takes at most {max_length} "
           r"arguments \({actual_length} given\)"
           .format(fname=_fname, max_length=max_length,
                   actual_length=actual_length))

    with pytest.raises(TypeError, match=msg):
        validate_args(_fname, args, min_fname_arg_count, compat_args)
Exemple #10
0
def test_not_all_defaults(i):
    bad_arg = "foo"
    msg = ("the '{arg}' parameter is not supported "
           r"in the pandas implementation of {func}\(\)".format(arg=bad_arg,
                                                                func=_fname))

    compat_args = OrderedDict()
    compat_args["foo"] = 2
    compat_args["bar"] = -1
    compat_args["baz"] = 3

    arg_vals = (1, -1, 3)

    with pytest.raises(ValueError, match=msg):
        validate_args(_fname, arg_vals[:i], 2, compat_args)
    def test_bad_arg_length_max_value_multiple(self):
        args = (None, None)
        compat_args = dict(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 = (r"{fname}\(\) takes at most {max_length} "
               r"arguments \({actual_length} given\)".format(
                   fname=self.fname,
                   max_length=max_length,
                   actual_length=actual_length))

        with tm.assert_raises_regex(TypeError, msg):
            validate_args(self.fname, args, min_fname_arg_count, compat_args)
def test_not_all_defaults(i):
    bad_arg = "foo"
    msg = ("the '{arg}' parameter is not supported "
           r"in the pandas implementation of {func}\(\)".
           format(arg=bad_arg, func=_fname))

    compat_args = OrderedDict()
    compat_args["foo"] = 2
    compat_args["bar"] = -1
    compat_args["baz"] = 3

    arg_vals = (1, -1, 3)

    with pytest.raises(ValueError, match=msg):
        validate_args(_fname, arg_vals[:i], 2, compat_args)
Exemple #13
0
    def test_bad_arg_length_max_value_single(self):
        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 = (r"{fname}\(\) takes at most {max_length} "
               r"argument \({actual_length} given\)".format(
                   fname=self.fname,
                   max_length=max_length,
                   actual_length=actual_length))

        with pytest.raises(TypeError, match=msg):
            validate_args(self.fname, args, min_fname_arg_count, compat_args)
    def test_not_all_defaults(self):
        bad_arg = 'foo'
        msg = ("the '{arg}' parameter is not supported "
               r"in the pandas implementation of {func}\(\)".
               format(arg=bad_arg, func=self.fname))

        compat_args = OrderedDict()
        compat_args['foo'] = 2
        compat_args['bar'] = -1
        compat_args['baz'] = 3

        arg_vals = (1, -1, 3)

        for i in range(1, 3):
            with tm.assert_raises_regex(ValueError, msg):
                validate_args(self.fname, arg_vals[:i], 2, compat_args)
Exemple #15
0
    def test_bad_arg_length_max_value_single(self):
        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 = (r"{fname}\(\) takes at most {max_length} "
               r"argument \({actual_length} given\)"
               .format(fname=self.fname, max_length=max_length,
                       actual_length=actual_length))

        with tm.assert_raises_regex(TypeError, msg):
            validate_args(self.fname, args,
                          min_fname_arg_count,
                          compat_args)
Exemple #16
0
    def test_not_all_defaults(self):
        bad_arg = 'foo'
        msg = ("the '{arg}' parameter is not supported "
               r"in the pandas implementation of {func}\(\)".
               format(arg=bad_arg, func=self.fname))

        compat_args = OrderedDict()
        compat_args['foo'] = 2
        compat_args['bar'] = -1
        compat_args['baz'] = 3

        arg_vals = (1, -1, 3)

        for i in range(1, 3):
            with tm.assert_raises_regex(ValueError, msg):
                validate_args(self.fname, arg_vals[:i], 2, compat_args)
Exemple #17
0
    def __call__(self, args, kwargs, fname=None,
                 max_fname_arg_count=None, method=None):
        if args or kwargs:
            fname = self.fname if fname is None else fname
            max_fname_arg_count = (self.max_fname_arg_count if
                                   max_fname_arg_count is None
                                   else max_fname_arg_count)
            method = self.method if method is None else method

            if method == 'args':
                validate_args(fname, args, max_fname_arg_count, self.defaults)
            elif method == 'kwargs':
                validate_kwargs(fname, kwargs, self.defaults)
            elif method == 'both':
                validate_args_and_kwargs(fname, args, kwargs,
                                         max_fname_arg_count,
                                         self.defaults)
            else:
                raise ValueError("invalid validation method "
                                 "'{method}'".format(method=method))
Exemple #18
0
    def __call__(self, args, kwargs, fname=None,
                 max_fname_arg_count=None, method=None):
        if args or kwargs:
            fname = self.fname if fname is None else fname
            max_fname_arg_count = (self.max_fname_arg_count if
                                   max_fname_arg_count is None
                                   else max_fname_arg_count)
            method = self.method if method is None else method

            if method == 'args':
                validate_args(fname, args, max_fname_arg_count, self.defaults)
            elif method == 'kwargs':
                validate_kwargs(fname, kwargs, self.defaults)
            elif method == 'both':
                validate_args_and_kwargs(fname, args, kwargs,
                                         max_fname_arg_count,
                                         self.defaults)
            else:
                raise ValueError("invalid validation method "
                                 "'{method}'".format(method=method))
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)
Exemple #20
0
 def test_bad_min_fname_arg_count(self):
     msg = "'max_fname_arg_count' must be non-negative"
     with tm.assert_raises_regex(ValueError, msg):
         validate_args(self.fname, (None,), -1, 'foo')
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_min_fname_arg_count(self):
     msg = "'max_fname_arg_count' must be non-negative"
     with tm.assert_raises_regex(ValueError, msg):
         validate_args(self.fname, (None,), -1, 'foo')
Exemple #23
0
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")