1 from test_support
import verify
, verbose
, TestFailed
, sortdict
2 from UserList
import UserList
8 print x
, y
, sortdict(z
)
20 f(1, 2, 3, *UserList([4, 5]))
21 f(1, 2, 3, **{'a':4, 'b':5})
22 f(1, 2, 3, *(4, 5), **{'a':6, 'b':7})
23 f(1, 2, 3, x
=4, y
=5, *(6, 7), **{'a':8, 'b':9})
27 except TypeError, err
:
28 print "TypeError:", err
30 print "should raise TypeError: not enough arguments; expected 1, got 0"
34 except TypeError, err
:
35 print "TypeError:", err
37 print "should raise TypeError: not enough arguments; expected 1, got 0"
41 except TypeError, err
:
42 print "TypeError:", err
44 print "should raise TypeError: not enough arguments; expected 1, got 0"
53 except TypeError, attr
:
56 print "should raise TypeError"
63 except TypeError, attr
:
66 print "should raise TypeError"
71 def __getitem__(self
, i
):
78 # make sure the function call doesn't stomp on the dictionary?
79 d
= {'a': 1, 'b': 2, 'c': 3}
85 verify(d
== d2
, "function call modified dictionary")
87 # what about willful misconduct?
89 kw
['x'] = locals() # yields a cyclic kw
92 kw
= saboteur(a
=1, **d
)
98 g(1, 2, 3, **{'x':4, 'y':5})
99 except TypeError, err
:
102 print "should raise TypeError: keyword parameter redefined"
105 g(1, 2, 3, a
=4, b
=5, *(6, 7), **{'a':8, 'b':9})
106 except TypeError, err
:
109 print "should raise TypeError: keyword parameter redefined"
113 except TypeError, err
:
116 print "should raise TypeError: keywords must be strings"
120 except TypeError, err
:
123 print "should raise TypeError: unexpected keyword argument: e"
127 except TypeError, err
:
130 print "should raise TypeError: * argument must be a tuple"
134 except TypeError, err
:
137 print "should raise TypeError: * argument must be a tuple"
141 except TypeError, err
:
144 print "should raise TypeError: * argument must be a tuple"
148 except TypeError, err
:
151 print "should raise TypeError: ** argument must be a dictionary"
155 except TypeError, err
:
158 print "should raise TypeError: ** argument must be a dictionary"
162 except TypeError, err
:
165 print "should raise TypeError: ** argument must be a dictionary"
169 except TypeError, err
:
172 print "should raise TypeError: dir() got multiple values for keyword argument 'b'"
181 a
, b
= f2(1, *(2, 3), **d
)
182 print len(a
), len(b
), b
== d
185 def method(self
, arg1
, arg2
):
189 print Foo
.method(*(x
, 1, 2))
190 print Foo
.method(x
, *(1, 2))
192 print Foo
.method(*(1, 2, 3))
193 except TypeError, err
:
196 print Foo
.method(1, *(2, 3))
197 except TypeError, err
:
200 # A PyCFunction that takes only positional parameters should allow an
201 # empty keyword dictionary to pass without a complaint, but raise a
202 # TypeError if the dictionary is non-empty.
209 raise TestFailed
, 'expected TypeError; no exception raised'
211 a
, b
, d
, e
, v
, k
= 'A', 'B', 'D', 'E', 'V', 'K'
214 for args
in ['', 'a', 'ab']:
215 for defargs
in ['', 'd', 'de']:
216 for vararg
in ['', 'v']:
217 for kwarg
in ['', 'k']:
218 name
= 'z' + args
+ defargs
+ vararg
+ kwarg
219 arglist
= list(args
) + map(
220 lambda x
: '%s="%s"' % (x
, x
), defargs
)
221 if vararg
: arglist
.append('*' + vararg
)
222 if kwarg
: arglist
.append('**' + kwarg
)
223 decl
= (('def %s(%s): print "ok %s", a, b, d, e, v, ' +
224 'type(k) is type ("") and k or sortdict(k)')
225 % (name
, ', '.join(arglist
), name
))
229 maxargs
[func
] = len(args
+ defargs
)
231 for name
in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']:
233 for args
in [(), (1, 2), (1, 2, 3, 4, 5)]:
234 for kwargs
in ['', 'a', 'd', 'ad', 'abde']:
236 for k
in kwargs
: kwdict
[k
] = k
+ k
237 print func
.func_name
, args
, sortdict(kwdict
), '->',
238 try: apply(func
, args
, kwdict
)
239 except TypeError, err
: print err