Cython has moved to github.

cython-devel

view tests/run/callargs.pyx @ 1622:4f0327bdebc9

test for temp allocation bug in call
author Robert Bradshaw <robertwb@math.washington.edu>
date Sat Jan 17 01:25:34 2009 -0800 (3 years ago)
parents d57e5d68d231
children 82d312a9f1fc
line source
1 __doc__ = u"""
2 >>> test_pos_args(h)
3 1 2 3 * 0 0
4 1 2 9 * 2 0
5 1 2 7 * 2 0
6 9 8 7 * 0 0
7 7 8 9 * 0 0
9 >>> test_kw_args(h)
10 1 2 3 * 0 0
11 1 2 9 * 2 1
12 1 2 7 * 2 1
13 1 2 9 * 2 2
14 1 2 9 * 2 2
15 1 2 9 * 2 3
17 >>> test_kw_args(e)
18 2 1
19 5 1
20 5 1
21 5 2
22 5 2
23 5 3
25 >>> test_kw(e)
26 0 1
27 0 2
28 0 2
29 0 1
31 >>> test_kw(g)
32 1
33 2
34 2
35 1
37 >>> test_pos_args(f)
38 3
39 5
40 5
41 3
42 3
44 >>> test_noargs(e)
45 0 0
46 >>> test_noargs(f)
47 0
48 >>> test_noargs(g)
49 0
51 # and some errors:
53 >>> test_noargs(h)
54 Traceback (most recent call last):
55 TypeError: h() takes at least 3 positional arguments (0 given)
57 >>> h(1,2, d=5)
58 Traceback (most recent call last):
59 TypeError: h() takes at least 3 positional arguments (2 given)
61 >>> f(1,2, d=5)
62 Traceback (most recent call last):
63 TypeError: f() got an unexpected keyword argument 'd'
64 >>> f(1, d=5)
65 Traceback (most recent call last):
66 TypeError: f() got an unexpected keyword argument 'd'
67 >>> f(d=5)
68 Traceback (most recent call last):
69 TypeError: f() got an unexpected keyword argument 'd'
71 >>> g(1,2, d=5)
72 Traceback (most recent call last):
73 TypeError: g() takes exactly 0 positional arguments (2 given)
74 >>> g(1,2)
75 Traceback (most recent call last):
76 TypeError: g() takes exactly 0 positional arguments (2 given)
77 >>> g(1)
78 Traceback (most recent call last):
79 TypeError: g() takes exactly 0 positional arguments (1 given)
81 >>> test_int_kwargs(e)
82 Traceback (most recent call last):
83 TypeError: e() keywords must be strings
84 >>> test_int_kwargs(f)
85 Traceback (most recent call last):
86 TypeError: f() keywords must be strings
87 >>> test_int_kwargs(g)
88 Traceback (most recent call last):
89 TypeError: g() keywords must be strings
90 >>> test_int_kwargs(h)
91 Traceback (most recent call last):
92 TypeError: h() keywords must be strings
94 >>> d()
95 Traceback (most recent call last):
96 TypeError: d() takes at least 1 positional argument (0 given)
97 >>> d(1)
98 1 1 0 0
99 >>> d(1,2)
100 1 2 0 0
101 >>> d(1,2,3)
102 1 2 1 0
104 >>> d(key=None)
105 Traceback (most recent call last):
106 TypeError: d() takes at least 1 positional argument (0 given)
107 >>> d(1, key=None)
108 1 1 0 1
109 >>> d(1,2, key=None)
110 1 2 0 1
111 >>> d(1,2,3, key=None)
112 1 2 1 1
114 >>> c()
115 10 20 0
116 >>> c(1)
117 1 20 0
118 >>> c(1,2)
119 1 2 0
120 >>> c(key=None)
121 10 20 1
122 >>> c(1, key=None)
123 1 20 1
124 >>> c(1,2, key=None)
125 1 2 1
127 """
129 def c(a=10, b=20, **kwds):
130 print a, b, len(kwds)
132 def d(a, b=1, *args, **kwds):
133 print a, b, len(args), len(kwds)
135 def e(*args, **kwargs):
136 print len(args), len(kwargs)
138 def f(*args):
139 print len(args)
141 def g(**kwargs):
142 print len(kwargs)
144 def h(a, b, c, *args, **kwargs):
145 print a, b, c, u'*', len(args), len(kwargs)
147 args = (9,8,7)
149 import sys
150 if sys.version_info[0] >= 3:
151 kwargs = {u"test" : u"toast"}
152 else:
153 kwargs = {"test" : u"toast"}
155 def test_kw_args(f):
156 f(1,2, c=3)
157 f(1,2, d=3, *args)
158 f(1,2, d=3, *(7,8,9))
159 f(1,2, d=3, *args, **kwargs)
160 f(1,2, d=3, *args, e=5)
161 f(1,2, d=3, *args, e=5, **kwargs)
163 def test_pos_args(f):
164 f(1,2,3)
165 f(1,2, *args)
166 f(1,2, *(7,8,9))
167 f(*args)
168 f(*(7,8,9))
170 def test_kw(f):
171 f(c=3)
172 f(d=3, e=5)
173 f(d=3, **kwargs)
174 f(**kwargs)
176 def test_noargs(f):
177 f()
179 def test_int_kwargs(f):
180 f(a=1,b=2,c=3, **{10:20,30:40})