From: Stefan Behnel Date: Thu, 16 Dec 2010 17:26:09 +0000 (+0100) Subject: working test for ticket #87 X-Git-Tag: 0.14.1rc0~13^2~22 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=65b6ca3426290334f923ff510222c3e93741b3d5;p=cython.git working test for ticket #87 --- diff --git a/tests/run/class_func_in_control_structures_T87.pyx b/tests/run/class_func_in_control_structures_T87.pyx new file mode 100644 index 00000000..ed810793 --- /dev/null +++ b/tests/run/class_func_in_control_structures_T87.pyx @@ -0,0 +1,58 @@ + +__doc__ = u""" +>>> d = Defined() +>>> n = NotDefined() +Traceback (most recent call last): +NameError: name 'NotDefined' is not defined +""" + +if True: + class Defined(object): + """ + >>> isinstance(Defined(), Defined) + True + """ + +if False: + class NotDefined(object): + """ + >>> NotDefined() # fails when defined + """ + +def test_class_cond(x): + """ + >>> Test, test = test_class_cond(True) + >>> test.A + 1 + >>> Test().A + 1 + >>> Test, test = test_class_cond(False) + >>> test.A + 2 + >>> Test().A + 2 + """ + if x: + class Test(object): + A = 1 + else: + class Test(object): + A = 2 + return Test, Test() + +def test_func_cond(x): + """ + >>> func = test_func_cond(True) + >>> func() + 1 + >>> func = test_func_cond(False) + >>> func() + 2 + """ + if x: + def func(): + return 1 + else: + def func(): + return 2 + return func