Cython has moved to github.
cython-devel
view tests/run/extstarargs.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 | 90e24d236a55 |
| children |
line source
1 __doc__ = u"""
2 >>> s = Silly(1,2,3, 'test')
3 >>> (spam,grail,swallow,creosote,onlyt,onlyk,tk) = (
4 ... s.spam,s.grail,s.swallow,s.creosote,s.onlyt,s.onlyk,s.tk)
6 >>> spam(1,2,3)
7 (1, 2, 3)
8 >>> spam(1,2)
9 Traceback (most recent call last):
10 TypeError: spam() takes exactly 3 positional arguments (2 given)
11 >>> spam(1,2,3,4)
12 Traceback (most recent call last):
13 TypeError: spam() takes exactly 3 positional arguments (4 given)
14 >>> spam(1,2,3, a=1) #doctest: +ELLIPSIS
15 Traceback (most recent call last):
16 TypeError: spam() got an unexpected keyword argument 'a'
18 >>> grail(1,2,3)
19 (1, 2, 3, ())
20 >>> grail(1,2,3,4)
21 (1, 2, 3, (4,))
22 >>> grail(1,2,3,4,5,6,7,8,9)
23 (1, 2, 3, (4, 5, 6, 7, 8, 9))
24 >>> grail(1,2)
25 Traceback (most recent call last):
26 TypeError: grail() takes at least 3 positional arguments (2 given)
27 >>> grail(1,2,3, a=1) #doctest: +ELLIPSIS
28 Traceback (most recent call last):
29 TypeError: grail() got an unexpected keyword argument 'a'
31 >>> swallow(1,2,3)
32 (1, 2, 3, ())
33 >>> swallow(1,2,3,4)
34 Traceback (most recent call last):
35 TypeError: swallow() takes exactly 3 positional arguments (4 given)
36 >>> swallow(1,2,3, a=1, b=2)
37 (1, 2, 3, (('a', 1), ('b', 2)))
38 >>> swallow(1,2,3, x=1)
39 Traceback (most recent call last):
40 TypeError: swallow() got multiple values for keyword argument 'x'
42 >>> creosote(1,2,3)
43 (1, 2, 3, (), ())
44 >>> creosote(1,2,3,4)
45 (1, 2, 3, (4,), ())
46 >>> creosote(1,2,3, a=1)
47 (1, 2, 3, (), (('a', 1),))
48 >>> creosote(1,2,3,4, a=1, b=2)
49 (1, 2, 3, (4,), (('a', 1), ('b', 2)))
50 >>> creosote(1,2,3,4, x=1)
51 Traceback (most recent call last):
52 TypeError: creosote() got multiple values for keyword argument 'x'
54 >>> onlyt(1)
55 (1,)
56 >>> onlyt(1,2)
57 (1, 2)
58 >>> onlyt(a=1)
59 Traceback (most recent call last):
60 TypeError: onlyt() got an unexpected keyword argument 'a'
61 >>> onlyt(1, a=2)
62 Traceback (most recent call last):
63 TypeError: onlyt() got an unexpected keyword argument 'a'
65 >>> onlyk(a=1)
66 (('a', 1),)
67 >>> onlyk(a=1, b=2)
68 (('a', 1), ('b', 2))
69 >>> onlyk(1)
70 Traceback (most recent call last):
71 TypeError: onlyk() takes exactly 0 positional arguments (1 given)
72 >>> onlyk(1, 2)
73 Traceback (most recent call last):
74 TypeError: onlyk() takes exactly 0 positional arguments (2 given)
75 >>> onlyk(1, a=1, b=2)
76 Traceback (most recent call last):
77 TypeError: onlyk() takes exactly 0 positional arguments (1 given)
79 >>> tk(a=1)
80 (('a', 1),)
81 >>> tk(a=1, b=2)
82 (('a', 1), ('b', 2))
83 >>> tk(1)
84 (1,)
85 >>> tk(1, 2)
86 (1, 2)
87 >>> tk(1, a=1, b=2)
88 (1, ('a', 1), ('b', 2))
89 """
91 import sys, re
92 if sys.version_info >= (2,6):
93 __doc__ = re.sub(u"(ELLIPSIS[^>]*Error: )[^\n]*\n", u"\\1...\n", __doc__, re.M)
95 cdef sorteditems(d):
96 l = list(d.items())
97 l.sort()
98 return tuple(l)
100 cdef class Silly:
102 def __init__(self, *a):
103 pass
105 def spam(self, x, y, z):
106 return (x, y, z)
108 def grail(self, x, y, z, *a):
109 return (x, y, z, a)
111 def swallow(self, x, y, z, **k):
112 return (x, y, z, sorteditems(k))
114 def creosote(self, x, y, z, *a, **k):
115 return (x, y, z, a, sorteditems(k))
117 def onlyt(self, *a):
118 return a
120 def onlyk(self, **k):
121 return sorteditems(k)
123 def tk(self, *a, **k):
124 return a + sorteditems(k)
