def test_args(self): def voo(a, b): pass argspec = getargspec(voo) e_sig = Signature(['a', 'b'], None, {}, None) sig = get_signature(argspec) self.assertEqual(sig, e_sig)
def test_keywords(self): def voo(a=1, b=2): pass argspec = getargspec(voo) e_sig = Signature([], None, {'a': 1, 'b': 2}, None) sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertEqual(get_default_value('a', argspec), 1) self.assertEqual(get_default_value('b', argspec), 2)
def test_keywords_and_kwargs(self): def voo(a=1, **b): pass argspec = getargspec(voo) e_sig = Signature([], None, {'a': 1}, 'b') sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertEqual(get_default_value('a', argspec), 1) self.assertRaises(NoDefaultError, get_default_value, 'b', argspec)
def test_varargs_and_kwargs(self): def voo(*a, **b): pass argspec = getargspec(voo) e_sig = Signature([], 'a', {}, 'b') sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertRaises(NoDefaultError, get_default_value, 'a', argspec) self.assertRaises(NoDefaultError, get_default_value, 'b', argspec)
def parse_sig_remaining_inputs( default, argspec, callargs, kwargs, errors, handled, on_error, fail_fast, ): sig = get_signature(argspec) for name, value in sorted(callargs.items()): if name in handled: continue handled.update([name]) # Only (validate) if the func is provided: if default is not IGNORE: try: default(name, value, argspec) except Exception as exc: func_name = get_func_name(default) default_value = callargs[name] try: index = sig.args.index(name) except ValueError: errors.append( KeywordError( exc, name, value, default_value, func_name, default, )) else: errors.append( PositionalError( exc, name, index, value, func_name, default, )) conditionally_raise_exc( exc=exc, on_error=on_error, errors=errors, fail_fast=fail_fast, )
def test_args_and_varargs(self): def voo(a, b, *c): pass argspec = getargspec(voo) e_sig = Signature(['a', 'b'], 'c', {}, None) sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertRaises(NoDefaultError, get_default_value, 'a', argspec) self.assertRaises(NoDefaultError, get_default_value, 'b', argspec) self.assertRaises(NoDefaultError, get_default_value, 'c', argspec)
def test_args_keywords_and_kwargs(self): def voo(a, b=2, **c): pass argspec = getargspec(voo) e_sig = Signature(['a'], None, {'b': 2}, 'c') sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertRaises(NoDefaultError, get_default_value, 'a', argspec) self.assertEqual(get_default_value('b', argspec), 2) self.assertRaises(NoDefaultError, get_default_value, 'c', argspec)
def test_args_and_keywords(self): def voo(a, b, d=3, e=4): pass argspec = getargspec(voo) e_sig = Signature(['a', 'b'], None, {'d': 3, 'e': 4}, None) sig = get_signature(argspec) self.assertEqual(sig, e_sig) self.assertRaises(NoDefaultError, get_default_value, 'a', argspec) self.assertRaises(NoDefaultError, get_default_value, 'b', argspec) self.assertEqual(get_default_value('d', argspec), 3) self.assertEqual(get_default_value('e', argspec), 4)