Example #1
0
 def test_validation(self):
     # No exceptions should be thrown
     compat_args = OrderedDict()
     compat_args['f'] = None
     compat_args['b'] = 1
     compat_args['ba'] = 's'
     kwargs = dict(f=None, b=1)
     validate_kwargs(self.fname, kwargs, compat_args)
Example #2
0
 def test_validation(self):
     # No exceptions should be thrown
     compat_args = OrderedDict()
     compat_args["f"] = None
     compat_args["b"] = 1
     compat_args["ba"] = "s"
     kwargs = dict(f=None, b=1)
     validate_kwargs(self.fname, kwargs, compat_args)
Example #3
0
 def test_validation(self):
     # No exceptions should be thrown
     compat_args = OrderedDict()
     compat_args['f'] = None
     compat_args['b'] = 1
     compat_args['ba'] = 's'
     kwargs = dict(f=None, b=1)
     validate_kwargs(self.fname, kwargs, compat_args)
Example #4
0
    def test_bad_kwarg(self):
        goodarg = "f"
        badarg = goodarg + "o"

        compat_args = OrderedDict()
        compat_args[goodarg] = "foo"
        compat_args[badarg + "o"] = "bar"
        kwargs = {goodarg: "foo", badarg: "bar"}
        msg = r"{fname}\(\) got an unexpected " r"keyword argument '{arg}'".format(fname=self.fname, arg=badarg)

        with tm.assertRaisesRegexp(TypeError, msg):
            validate_kwargs(self.fname, kwargs, compat_args)
Example #5
0
    def test_bad_kwarg(self):
        goodarg = 'f'
        badarg = goodarg + 'o'

        kwargs = {goodarg: 'foo', badarg: 'bar'}
        compat_args = (goodarg, badarg + 'o')
        fname = 'func'

        msg = ("{fname}\(\) got an unexpected "
               "keyword argument '{arg}'".format(fname=fname, arg=badarg))

        with tm.assertRaisesRegexp(TypeError, msg):
            validate_kwargs(fname, kwargs, *compat_args)
Example #6
0
    def test_bad_kwarg(self):
        goodarg = 'f'
        badarg = goodarg + 'o'

        compat_args = OrderedDict()
        compat_args[goodarg] = 'foo'
        compat_args[badarg + 'o'] = 'bar'
        kwargs = {goodarg: 'foo', badarg: 'bar'}
        msg = ("{fname}\(\) got an unexpected "
               "keyword argument '{arg}'".format(fname=self.fname, arg=badarg))

        with tm.assertRaisesRegexp(TypeError, msg):
            validate_kwargs(self.fname, kwargs, compat_args)
Example #7
0
    def test_bad_kwarg(self):
        goodarg = 'f'
        badarg = goodarg + 'o'

        compat_args = OrderedDict()
        compat_args[goodarg] = 'foo'
        compat_args[badarg + 'o'] = 'bar'
        kwargs = {goodarg: 'foo', badarg: 'bar'}
        msg = (r"{fname}\(\) got an unexpected "
               r"keyword argument '{arg}'".format(
                   fname=self.fname, arg=badarg))

        with tm.assertRaisesRegexp(TypeError, msg):
            validate_kwargs(self.fname, kwargs, compat_args)
Example #8
0
    def test_bad_kwarg(self):
        goodarg = 'f'
        badarg = goodarg + 'o'

        kwargs = {goodarg: 'foo', badarg: 'bar'}
        compat_args = (goodarg, badarg + 'o')
        fname = 'func'

        msg = ("{fname}\(\) got an unexpected "
               "keyword argument '{arg}'".format(
                   fname=fname, arg=badarg))

        with tm.assertRaisesRegexp(TypeError, msg):
            validate_kwargs(fname, kwargs, *compat_args)
Example #9
0
    def test_not_all_none(self):
        bad_arg = 'foo'
        msg = (r"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'] = 1
        compat_args['bar'] = 's'
        compat_args['baz'] = None

        kwarg_keys = ('foo', 'bar', 'baz')
        kwarg_vals = (2, 's', None)

        for i in range(1, 3):
            kwargs = dict(zip(kwarg_keys[:i], kwarg_vals[:i]))

            with tm.assertRaisesRegexp(ValueError, msg):
                validate_kwargs(self.fname, kwargs, compat_args)
Example #10
0
    def __call__(self, args, kwargs, fname=None,
                 max_fname_arg_count=None, method=None):
        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))
Example #11
0
    def test_not_all_none(self):
        bad_arg = "foo"
        msg = r"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"] = 1
        compat_args["bar"] = "s"
        compat_args["baz"] = None

        kwarg_keys = ("foo", "bar", "baz")
        kwarg_vals = (2, "s", None)

        for i in range(1, 3):
            kwargs = dict(zip(kwarg_keys[:i], kwarg_vals[:i]))

            with tm.assertRaisesRegexp(ValueError, msg):
                validate_kwargs(self.fname, kwargs, compat_args)
Example #12
0
    def test_not_all_none(self):
        bad_arg = 'foo'
        msg = (r"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'] = 1
        compat_args['bar'] = 's'
        compat_args['baz'] = None

        kwarg_keys = ('foo', 'bar', 'baz')
        kwarg_vals = (2, 's', None)

        for i in range(1, 3):
            kwargs = dict(zip(kwarg_keys[:i],
                              kwarg_vals[:i]))

            with tm.assertRaisesRegexp(ValueError, msg):
                validate_kwargs(self.fname, kwargs, compat_args)
Example #13
0
 def test_validation(self):
     # No exceptions should be thrown
     compat_args = ('f', 'b', 'ba')
     kwargs = {'f': 'foo', 'b': 'bar'}
     validate_kwargs('func', kwargs, *compat_args)
Example #14
0
 def test_validation(self):
     # No exceptions should be thrown
     compat_args = ('f', 'b', 'ba')
     kwargs = {'f': 'foo', 'b': 'bar'}
     validate_kwargs('func', kwargs, *compat_args)