from test
.test_support
import verify
, verbose
, TestFailed
, sortdict
from UserList
import UserList
f(1, 2, 3, *UserList([4, 5]))
f(1, 2, 3, **{'a':4, 'b':5})
f(1, 2, 3, *(4, 5), **{'a':6, 'b':7})
f(1, 2, 3, x
=4, y
=5, *(6, 7), **{'a':8, 'b':9})
# Verify clearing of SF bug #733667
print "should raise TypeError: e() got an unexpected keyword argument 'c'"
print "should raise TypeError: not enough arguments; expected 1, got 0"
print "should raise TypeError: not enough arguments; expected 1, got 0"
print "should raise TypeError: not enough arguments; expected 1, got 0"
print "should raise TypeError"
print "should raise TypeError"
def __getitem__(self
, i
):
print "should raise TypeError"
# make sure the function call doesn't stomp on the dictionary?
d
= {'a': 1, 'b': 2, 'c': 3}
verify(d
== d2
, "function call modified dictionary")
# what about willful misconduct?
kw
['x'] = locals() # yields a cyclic kw
g(1, 2, 3, **{'x':4, 'y':5})
print "should raise TypeError: keyword parameter redefined"
g(1, 2, 3, a
=4, b
=5, *(6, 7), **{'a':8, 'b':9})
print "should raise TypeError: keyword parameter redefined"
print "should raise TypeError: keywords must be strings"
print "should raise TypeError: unexpected keyword argument: e"
print "should raise TypeError: * argument must be a tuple"
print "should raise TypeError: * argument must be a tuple"
print "should raise TypeError: * argument must be a tuple"
print "should raise TypeError: ** argument must be a dictionary"
print "should raise TypeError: ** argument must be a dictionary"
print "should raise TypeError: ** argument must be a dictionary"
print "should raise TypeError: dir() got multiple values for keyword argument 'b'"
a
, b
= f2(1, *(2, 3), **d
)
print len(a
), len(b
), b
== d
def method(self
, arg1
, arg2
):
print Foo
.method(*(x
, 1, 2))
print Foo
.method(x
, *(1, 2))
print Foo
.method(*(1, 2, 3))
print 'expected a TypeError for unbound method call'
print Foo
.method(1, *(2, 3))
print 'expected a TypeError for unbound method call'
# A PyCFunction that takes only positional parameters should allow an
# empty keyword dictionary to pass without a complaint, but raise a
# TypeError if the dictionary is non-empty.
raise TestFailed
, 'expected TypeError; no exception raised'
a
, b
, d
, e
, v
, k
= 'A', 'B', 'D', 'E', 'V', 'K'
for args
in ['', 'a', 'ab']:
for defargs
in ['', 'd', 'de']:
name
= 'z' + args
+ defargs
+ vararg
+ kwarg
arglist
= list(args
) + map(
lambda x
: '%s="%s"' % (x
, x
), defargs
)
if vararg
: arglist
.append('*' + vararg
)
if kwarg
: arglist
.append('**' + kwarg
)
decl
= (('def %s(%s): print "ok %s", a, b, d, e, v, ' +
'type(k) is type ("") and k or sortdict(k)')
% (name
, ', '.join(arglist
), name
))
maxargs
[func
] = len(args
+ defargs
)
for name
in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']:
for args
in [(), (1, 2), (1, 2, 3, 4, 5)]:
for kwargs
in ['', 'a', 'd', 'ad', 'abde']:
for k
in kwargs
: kwdict
[k
] = k
+ k
print func
.func_name
, args
, sortdict(kwdict
), '->',
try: func(*args
, **kwdict
)
except TypeError, err
: print err