Skip to content

Commit

Permalink
show that you could actually write generator functions with and in Re…
Browse files Browse the repository at this point in the history
…strictedPython code and call it from outside.
  • Loading branch information
loechel committed Oct 3, 2018
1 parent f5a9eb2 commit ae3d912
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/transformer/test_yield.py
Expand Up @@ -17,6 +17,11 @@ def test_yield(c_exec):
result = c_exec(YIELD_EXAMPLE)
assert result.errors == ()
assert result.code is not None
local = {}
exec(result.code, {}, local)
no_yield = local['no_yield']
exec_result = [elem for elem in no_yield()]
assert exec_result == [42]


YIELD_FORM_EXAMPLE = """
Expand All @@ -35,6 +40,17 @@ def test_yield_from(c_exec):
assert result.errors == ()
assert result.code is not None

def my_generator():
my_list = [1, 2, 3, 4, 5]
for elem in my_list:
yield(elem)

local = {}
exec(result.code, {}, local)
reader_wapper = local['reader_wapper']
exec_result = [elem for elem in reader_wapper(my_generator())]
assert exec_result == [1, 2, 3, 4, 5]


# Modified Example from http://stackabuse.com/python-async-await-tutorial/
ASYNCIO_YIELD_FORM_EXAMPLE = """
Expand Down

0 comments on commit ae3d912

Please sign in to comment.