diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/fun-calldblstar.py | 17 | ||||
| -rw-r--r-- | tests/basics/fun-callstar.py | 33 | ||||
| -rw-r--r-- | tests/basics/fun-callstardblstar.py | 17 | ||||
| -rw-r--r-- | tests/basics/gen-yield-from-ducktype.py | 44 | ||||
| -rw-r--r-- | tests/basics/gen-yield-from-iter.py | 8 | ||||
| -rw-r--r-- | tests/basics/iter-of-iter.py | 8 |
6 files changed, 127 insertions, 0 deletions
diff --git a/tests/basics/fun-calldblstar.py b/tests/basics/fun-calldblstar.py new file mode 100644 index 000000000..aae9828cf --- /dev/null +++ b/tests/basics/fun-calldblstar.py @@ -0,0 +1,17 @@ +# test calling a function with keywords given by **dict + +def f(a, b): + print(a, b) + +f(1, **{'b':2}) +f(1, **{'b':val for val in range(1)}) + +# test calling a method with keywords given by **dict + +class A: + def f(self, a, b): + print(a, b) + +a = A() +a.f(1, **{'b':2}) +a.f(1, **{'b':val for val in range(1)}) diff --git a/tests/basics/fun-callstar.py b/tests/basics/fun-callstar.py new file mode 100644 index 000000000..255563b26 --- /dev/null +++ b/tests/basics/fun-callstar.py @@ -0,0 +1,33 @@ +# function calls with *pos + +def foo(a, b, c): + print(a, b, c) + +foo(*(1, 2, 3)) +foo(1, *(2, 3)) +foo(1, 2, *(3,)) +foo(1, 2, 3, *()) + +# Another sequence type +foo(1, 2, *[100]) + +# Iterator +foo(*range(3)) + +# method calls with *pos + +class A: + def foo(self, a, b, c): + print(a, b, c) + +a = A() +a.foo(*(1, 2, 3)) +a.foo(1, *(2, 3)) +a.foo(1, 2, *(3,)) +a.foo(1, 2, 3, *()) + +# Another sequence type +a.foo(1, 2, *[100]) + +# Iterator +a.foo(*range(3)) diff --git a/tests/basics/fun-callstardblstar.py b/tests/basics/fun-callstardblstar.py new file mode 100644 index 000000000..f2fd29107 --- /dev/null +++ b/tests/basics/fun-callstardblstar.py @@ -0,0 +1,17 @@ +# test calling a function with *tuple and **dict + +def f(a, b, c, d): + print(a, b, c, d) + +f(*(1, 2), **{'c':3, 'd':4}) +f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) + +# test calling a method with *tuple and **dict + +class A: + def f(self, a, b, c, d): + print(a, b, c, d) + +a = A() +a.f(*(1, 2), **{'c':3, 'd':4}) +a.f(*(1, 2), **{['c', 'd'][i]:(3 + i) for i in range(2)}) diff --git a/tests/basics/gen-yield-from-ducktype.py b/tests/basics/gen-yield-from-ducktype.py new file mode 100644 index 000000000..aa0109c91 --- /dev/null +++ b/tests/basics/gen-yield-from-ducktype.py @@ -0,0 +1,44 @@ +class MyGen: + + def __init__(self): + self.v = 0 + + def __iter__(self): + return self + + def __next__(self): + self.v += 1 + if self.v > 5: + raise StopIteration + return self.v + +def gen(): + yield from MyGen() + +def gen2(): + yield from gen() + +print(list(gen())) +print(list(gen2())) + + +class Incrementer: + + def __iter__(self): + return self + + def __next__(self): + return self.send(None) + + def send(self, val): + if val is None: + return "Incrementer initialized" + return val + 1 + +def gen3(): + yield from Incrementer() + +g = gen3() +print(next(g)) +print(g.send(5)) +print(g.send(100)) diff --git a/tests/basics/gen-yield-from-iter.py b/tests/basics/gen-yield-from-iter.py new file mode 100644 index 000000000..2d06328fb --- /dev/null +++ b/tests/basics/gen-yield-from-iter.py @@ -0,0 +1,8 @@ +def gen(): + yield from (1, 2, 3) + +def gen2(): + yield from gen() + +print(list(gen())) +print(list(gen2())) diff --git a/tests/basics/iter-of-iter.py b/tests/basics/iter-of-iter.py new file mode 100644 index 000000000..93368612b --- /dev/null +++ b/tests/basics/iter-of-iter.py @@ -0,0 +1,8 @@ +i = iter(iter((1, 2, 3))) +print(list(i)) +i = iter(iter([1, 2, 3])) +print(list(i)) +i = iter(iter({1:2, 3:4, 5:6})) +print(list(i)) +i = iter(iter({1, 2, 3})) +print(list(i)) |
