From 65b6ca3426290334f923ff510222c3e93741b3d5 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Thu, 16 Dec 2010 18:26:09 +0100 Subject: [PATCH] working test for ticket #87 --- .../class_func_in_control_structures_T87.pyx | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/run/class_func_in_control_structures_T87.pyx 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 -- 2.26.2