working test for ticket #87
authorStefan Behnel <scoder@users.berlios.de>
Thu, 16 Dec 2010 17:26:09 +0000 (18:26 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 16 Dec 2010 17:26:09 +0000 (18:26 +0100)
tests/run/class_func_in_control_structures_T87.pyx [new file with mode: 0644]

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 (file)
index 0000000..ed81079
--- /dev/null
@@ -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