1 from test
.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 'expected a TypeError for unbound method call'
198 print Foo
.method(1, *(2, 3))
199 except TypeError, err
:
202 print 'expected a TypeError for unbound method call'
204 # A PyCFunction that takes only positional parameters should allow an
205 # empty keyword dictionary to pass without a complaint, but raise a
206 # TypeError if the dictionary is non-empty.
213 raise TestFailed
, 'expected TypeError; no exception raised'
215 a
, b
, d
, e
, v
, k
= 'A', 'B', 'D', 'E', 'V', 'K'
218 for args
in ['', 'a', 'ab']:
219 for defargs
in ['', 'd', 'de']:
220 for vararg
in ['', 'v']:
221 for kwarg
in ['', 'k']:
222 name
= 'z' + args
+ defargs
+ vararg
+ kwarg
223 arglist
= list(args
) + map(
224 lambda x
: '%s="%s"' % (x
, x
), defargs
)
225 if vararg
: arglist
.append('*' + vararg
)
226 if kwarg
: arglist
.append('**' + kwarg
)
227 decl
= (('def %s(%s): print "ok %s", a, b, d, e, v, ' +
228 'type(k) is type ("") and k or sortdict(k)')
229 % (name
, ', '.join(arglist
), name
))
233 maxargs
[func
] = len(args
+ defargs
)
235 for name
in ['za', 'zade', 'zabk', 'zabdv', 'zabdevk']:
237 for args
in [(), (1, 2), (1, 2, 3, 4, 5)]:
238 for kwargs
in ['', 'a', 'd', 'ad', 'abde']:
240 for k
in kwargs
: kwdict
[k
] = k
+ k
241 print func
.func_name
, args
, sortdict(kwdict
), '->',
242 try: func(*args
, **kwdict
)
243 except TypeError, err
: print err