Commit 416e4035 authored by Stefan Behnel's avatar Stefan Behnel

more star args tests

parent a21ec3d4
__doc__ = """ __doc__ = """
>>> spam(1,2,3) >>> spam(1,2,3)
(1, 2, 3)
>>> spam(1,2) >>> spam(1,2)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given) TypeError: function takes exactly 3 arguments (2 given)
...@@ -11,8 +12,11 @@ __doc__ = """ ...@@ -11,8 +12,11 @@ __doc__ = """
TypeError: 'a' is an invalid keyword argument for this function TypeError: 'a' is an invalid keyword argument for this function
>>> grail(1,2,3) >>> grail(1,2,3)
(1, 2, 3, ())
>>> grail(1,2,3,4) >>> grail(1,2,3,4)
(1, 2, 3, (4,))
>>> grail(1,2,3,4,5,6,7,8,9) >>> grail(1,2,3,4,5,6,7,8,9)
(1, 2, 3, (4, 5, 6, 7, 8, 9))
>>> grail(1,2) >>> grail(1,2)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: function takes exactly 3 arguments (2 given) TypeError: function takes exactly 3 arguments (2 given)
...@@ -21,31 +25,87 @@ __doc__ = """ ...@@ -21,31 +25,87 @@ __doc__ = """
TypeError: 'a' is an invalid keyword argument for this function TypeError: 'a' is an invalid keyword argument for this function
>>> swallow(1,2,3) >>> swallow(1,2,3)
(1, 2, 3, ())
>>> swallow(1,2,3,4) >>> swallow(1,2,3,4)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: function takes at most 3 positional arguments (4 given) TypeError: function takes at most 3 positional arguments (4 given)
>>> swallow(1,2,3, a=1, b=2) >>> swallow(1,2,3, a=1, b=2)
(1, 2, 3, (('a', 1), ('b', 2)))
>>> swallow(1,2,3, x=1) >>> swallow(1,2,3, x=1)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name TypeError: keyword parameter 'x' was given by position and by name
>>> creosote(1,2,3) >>> creosote(1,2,3)
(1, 2, 3, (), ())
>>> creosote(1,2,3,4) >>> creosote(1,2,3,4)
(1, 2, 3, (4,), ())
>>> creosote(1,2,3, a=1) >>> creosote(1,2,3, a=1)
(1, 2, 3, (), (('a', 1),))
>>> creosote(1,2,3,4, a=1, b=2) >>> creosote(1,2,3,4, a=1, b=2)
(1, 2, 3, (4,), (('a', 1), ('b', 2)))
>>> creosote(1,2,3,4, x=1) >>> creosote(1,2,3,4, x=1)
Traceback (most recent call last): Traceback (most recent call last):
TypeError: keyword parameter 'x' was given by position and by name TypeError: keyword parameter 'x' was given by position and by name
>>> onlyt(1)
(1,)
>>> onlyt(1,2)
(1, 2)
>>> onlyt(a=1)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyt(1, a=2)
Traceback (most recent call last):
TypeError: 'a' is an invalid keyword argument for this function
>>> onlyk(a=1)
(('a', 1),)
>>> onlyk(a=1, b=2)
(('a', 1), ('b', 2))
>>> onlyk(1)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (1 given)
>>> onlyk(1, 2)
Traceback (most recent call last):
TypeError: function takes at most 0 positional arguments (2 given)
>>> onlyk(1, a=1, b=2)
Traceback (most recent call last):
TypeError: function takes at most 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 = d.items()
l.sort()
return tuple(l)
def spam(x, y, z): def spam(x, y, z):
pass return (x, y, z)
def grail(x, y, z, *a): def grail(x, y, z, *a):
pass return (x, y, z, a)
def swallow(x, y, z, **k): def swallow(x, y, z, **k):
pass return (x, y, z, sorteditems(k))
def creosote(x, y, z, *a, **k): def creosote(x, y, z, *a, **k):
pass return (x, y, z, a, sorteditems(k))
def onlyt(*a):
return a
def onlyk(**k):
return sorteditems(k)
def tk(*a, **k):
return a + sorteditems(k)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment