extended test cases for tickets #600 and #598
authorStefan Behnel <scoder@users.berlios.de>
Thu, 25 Nov 2010 18:18:06 +0000 (19:18 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 25 Nov 2010 18:18:06 +0000 (19:18 +0100)
tests/run/genexpr_iterable_lookup_T600.pyx
tests/run/list_comp_in_closure_T598.pyx

index 37d6c9f589e5e59738a05b9bbf8c1b399b1e0a76..e41148fa38984d81274f46380e0b8dc5fd644982 100644 (file)
@@ -16,3 +16,18 @@ def list_genexpr_iterable_lookup():
     result = list( x*2 for x in x if x % 2 == 0 )
     assert x == (0,1,2,3,4,5)
     return result
+
+@cython.test_assert_path_exists('//ComprehensionNode')
+@cython.test_fail_if_path_exists('//SimpleCallNode')
+def genexpr_iterable_in_closure():
+    """
+    >>> genexpr_iterable_in_closure()
+    [0, 4, 8]
+    """
+    x = 'abc'
+    def f():
+        return x
+    result = list( x*2 for x in x if x % 2 == 0 )
+    assert x == 'abc' # don't leak in Py3 code
+    assert f() == 'abc' # don't leak in Py3 code
+    return result
index 5246df2747e1cf9293a19a4e87721273fcc7f694..3f39c9aaf6997cac1982894cfc2a227a3feaa9ca 100644 (file)
@@ -25,3 +25,17 @@ def genexpr_in_closure():
     assert x == 'abc' # don't leak in Py3 code
     assert f() == 'abc' # don't leak in Py3 code
     return result
+
+def genexpr_scope_in_closure():
+    """
+    >>> genexpr_scope_in_closure()
+    [0, 4, 8]
+    """
+    i = 2
+    x = 'abc'
+    def f():
+        return i, x
+    result = list( x*i for x in range(5) if x % 2 == 0 )
+    assert x == 'abc' # don't leak in Py3 code
+    assert f() == 2,'abc' # don't leak in Py3 code
+    return result