From: Stefan Behnel Date: Thu, 25 Nov 2010 14:54:32 +0000 (+0100) Subject: test that functions that do not need a closure know they do not need it X-Git-Tag: 0.14.alpha0~84 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=03f1a3ce8b3ff97527723efea3f6a66b79eea17f;p=cython.git test that functions that do not need a closure know they do not need it --- diff --git a/tests/run/closures_T82.pyx b/tests/run/closures_T82.pyx index cb7f9c1c..cbb0a4df 100644 --- a/tests/run/closures_T82.pyx +++ b/tests/run/closures_T82.pyx @@ -1,4 +1,6 @@ +cimport cython + def add_n(int n): """ >>> f = add_n(3) @@ -185,6 +187,12 @@ def more_inner_funcs(x): return f(a_f), g(b_g), h(b_h) return resolve + +@cython.test_assert_path_exists("//DefNode//DefNode//DefNode//DefNode", + "//DefNode[@needs_outer_scope = False]", # deep_inner() + "//DefNode//DefNode//DefNode//DefNode[@needs_closure = False]", # h() + ) +@cython.test_fail_if_path_exists("//DefNode//DefNode[@needs_outer_scope = False]") def deep_inner(): """ >>> deep_inner()() @@ -199,6 +207,12 @@ def deep_inner(): return g() return f() + +@cython.test_assert_path_exists("//DefNode//DefNode//DefNode", + "//DefNode//DefNode//DefNode[@needs_outer_scope = False]", # a() + "//DefNode//DefNode//DefNode[@needs_closure = False]", # a(), g(), h() + ) +@cython.test_fail_if_path_exists("//DefNode//DefNode//DefNode[@needs_closure = True]") # a(), g(), h() def deep_inner_sibling(): """ >>> deep_inner_sibling()() @@ -206,8 +220,10 @@ def deep_inner_sibling(): """ cdef int x = 1 def f(): + def a(): + return 1 def g(): - return x+1 + return x+a() def h(): return g() return h