summaryrefslogtreecommitdiff
path: root/tests/run/extstarargs.pyx
blob: b657b42fd01be3010620984abb321292d90b2fc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
__doc__ = u"""
    >>> s = Silly(1,2,3, 'test')
    >>> (spam,grail,swallow,creosote,onlyt,onlyk,tk) = (
    ...     s.spam,s.grail,s.swallow,s.creosote,s.onlyt,s.onlyk,s.tk)

    >>> spam(1,2,3)
    (1, 2, 3)
    >>> spam(1,2)
    Traceback (most recent call last):
    TypeError: spam() takes exactly 3 positional arguments (2 given)
    >>> spam(1,2,3,4)
    Traceback (most recent call last):
    TypeError: spam() takes exactly 3 positional arguments (4 given)
    >>> spam(1,2,3, a=1) #doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: spam() got an unexpected keyword argument 'a'

    >>> grail(1,2,3)
    (1, 2, 3, ())
    >>> grail(1,2,3,4)
    (1, 2, 3, (4,))
    >>> grail(1,2,3,4,5,6,7,8,9)
    (1, 2, 3, (4, 5, 6, 7, 8, 9))
    >>> grail(1,2)
    Traceback (most recent call last):
    TypeError: grail() takes at least 3 positional arguments (2 given)
    >>> grail(1,2,3, a=1) #doctest: +ELLIPSIS
    Traceback (most recent call last):
    TypeError: grail() got an unexpected keyword argument 'a'

    >>> swallow(1,2,3)
    (1, 2, 3, ())
    >>> swallow(1,2,3,4)
    Traceback (most recent call last):
    TypeError: swallow() takes exactly 3 positional arguments (4 given)
    >>> swallow(1,2,3, a=1, b=2)
    (1, 2, 3, (('a', 1), ('b', 2)))
    >>> swallow(1,2,3, x=1)
    Traceback (most recent call last):
    TypeError: swallow() got multiple values for keyword argument 'x'

    >>> creosote(1,2,3)
    (1, 2, 3, (), ())
    >>> creosote(1,2,3,4)
    (1, 2, 3, (4,), ())
    >>> creosote(1,2,3, a=1)
    (1, 2, 3, (), (('a', 1),))
    >>> creosote(1,2,3,4, a=1, b=2)
    (1, 2, 3, (4,), (('a', 1), ('b', 2)))
    >>> creosote(1,2,3,4, x=1)
    Traceback (most recent call last):
    TypeError: creosote() got multiple values for keyword argument 'x'

    >>> onlyt(1)
    (1,)
    >>> onlyt(1,2)
    (1, 2)
    >>> onlyt(a=1)
    Traceback (most recent call last):
    TypeError: onlyt() got an unexpected keyword argument 'a'
    >>> onlyt(1, a=2)
    Traceback (most recent call last):
    TypeError: onlyt() got an unexpected keyword argument 'a'

    >>> onlyk(a=1)
    (('a', 1),)
    >>> onlyk(a=1, b=2)
    (('a', 1), ('b', 2))
    >>> onlyk(1)
    Traceback (most recent call last):
    TypeError: onlyk() takes exactly 0 positional arguments (1 given)
    >>> onlyk(1, 2)
    Traceback (most recent call last):
    TypeError: onlyk() takes exactly 0 positional arguments (2 given)
    >>> onlyk(1, a=1, b=2)
    Traceback (most recent call last):
    TypeError: onlyk() takes exactly 0 positional arguments (1 given)

    >>> tk(a=1)
    (('a', 1),)
    >>> tk(a=1, b=2)
    (('a', 1), ('b', 2))
    >>> tk(1)
    (1,)
    >>> tk(1, 2)
    (1, 2)
    >>> tk(1, a=1, b=2)
    (1, ('a', 1), ('b', 2))
"""


cdef sorteditems(d):
    l = list(d.items())
    l.sort()
    return tuple(l)


cdef class Silly:

    def __init__(self, *a):
        pass

    def spam(self, x, y, z):
        return (x, y, z)

    def grail(self, x, y, z, *a):
        return (x, y, z, a)

    def swallow(self, x, y, z, **k):
        return (x, y, z, sorteditems(k))

    def creosote(self, x, y, z, *a, **k):
        return (x, y, z, a, sorteditems(k))

    def onlyt(self, *a):
        return a

    def onlyk(self, **k):
        return sorteditems(k)

    def tk(self, *a, **k):
        return a + sorteditems(k)