test fixes
[cython.git] / tests / run / genexpr_iterable_lookup_T600.pyx
1
2 cimport cython
3
4 @cython.test_assert_path_exists('//ComprehensionNode')
5 @cython.test_fail_if_path_exists('//SimpleCallNode')
6 def list_genexpr_iterable_lookup():
7     """
8     >>> x = (0,1,2,3,4,5)
9     >>> [ x*2 for x in x if x % 2 == 0 ]  # leaks in Py2 but finds the right 'x'
10     [0, 4, 8]
11
12     >>> list_genexpr_iterable_lookup()
13     [0, 4, 8]
14     """
15     x = (0,1,2,3,4,5)
16     result = list( x*2 for x in x if x % 2 == 0 )
17     assert x == (0,1,2,3,4,5)
18     return result
19
20 @cython.test_assert_path_exists('//ComprehensionNode')
21 @cython.test_fail_if_path_exists('//SingleAssignmentNode//SimpleCallNode')
22 def genexpr_iterable_in_closure():
23     """
24     >>> genexpr_iterable_in_closure()
25     [0, 4, 8]
26     """
27     x = 'abc'
28     def f():
29         return x
30     result = list( x*2 for x in x if x % 2 == 0 )
31     assert x == 'abc' # don't leak in Py3 code
32     assert f() == 'abc' # don't leak in Py3 code
33     return result