From 9cf498c8e57f97b319562a87d09a03a5ee6214fb Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Fri, 7 Jan 2011 10:59:11 +0300 Subject: [PATCH] Add new tests for generators --- tests/run/generators.pyx | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/run/generators.pyx b/tests/run/generators.pyx index d435d469..fe2efb5f 100644 --- a/tests/run/generators.pyx +++ b/tests/run/generators.pyx @@ -207,3 +207,40 @@ def generator_nonlocal(): yield x return g return f(1) + +def test_nested(a, b, c): + """ + >>> obj = test_nested(1, 2, 3) + >>> [i() for i in obj] + [1, 2, 3, 4] + """ + def one(): + return a + def two(): + return b + def three(): + return c + def new_closure(a, b): + def sum(): + return a + b + return sum + yield one + yield two + yield three + yield new_closure(a, c) + + +def tolist(func): + def wrapper(*args, **kwargs): + return list(func(*args, **kwargs)) + return wrapper + +@tolist +def test_decorated(*args): + """ + >>> test_decorated(1, 2, 3) + [1, 2, 3] + """ + for i in args: + yield i + -- 2.26.2