Commit 1c864457 authored by Stefan Behnel's avatar Stefan Behnel

add test for generator expression under PEP 479

parent b4383a54
...@@ -133,3 +133,24 @@ def test_yield_from_gen(): ...@@ -133,3 +133,24 @@ def test_yield_from_gen():
""" """
x = yield from test_return_value() x = yield from test_return_value()
print("RETURN: %s" % x) print("RETURN: %s" % x)
def test_genexpr(it):
"""
>>> list(test_genexpr(iter([])))
[]
>>> list(test_genexpr(iter([1, 2])))
[1]
>>> list(test_genexpr(iter([1])))
Traceback (most recent call last):
RuntimeError: generator raised StopIteration
>>> list(test_genexpr(iter([1, 2, 3])))
Traceback (most recent call last):
RuntimeError: generator raised StopIteration
>>> list(test_genexpr(iter([1, 2])))
[1]
"""
return (x for x in it if next(it))
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