test case for ticket #228
authorStefan Behnel <scoder@users.berlios.de>
Tue, 3 Mar 2009 17:56:09 +0000 (18:56 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Tue, 3 Mar 2009 17:56:09 +0000 (18:56 +0100)
tests/bugs/funcexc_iter_T228.pyx [new file with mode: 0644]

diff --git a/tests/bugs/funcexc_iter_T228.pyx b/tests/bugs/funcexc_iter_T228.pyx
new file mode 100644 (file)
index 0000000..f15251d
--- /dev/null
@@ -0,0 +1,55 @@
+__doc__ = u"""
+>>> def py_iterator():
+...    if True: return
+...    yield None
+
+>>> list(py_iterator())
+[]
+>>> list(cy_iterator())
+[]
+
+>>> try:
+...     raise ValueError
+... except:
+...     print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+...     a = list(py_iterator())
+...     print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+...     a = list(cy_iterator())
+...     print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+True
+True
+True
+
+>>> if IS_PY3: print(sys.exc_info()[0] is None or sys.exc_info()[0])
+... else: print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+True
+
+>>> double_raise(py_iterator)
+True
+True
+True
+
+>>> if IS_PY3: print(sys.exc_info()[0] is None or sys.exc_info()[0])
+... else: print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+True
+"""
+
+import sys
+
+IS_PY3 = sys.version_info[0] >= 3
+
+cdef class cy_iterator(object):
+    def __iter__(self):
+        return self
+    def __next__(self):
+        raise StopIteration
+
+def double_raise(py_iterator):
+    try:
+        raise ValueError
+    except:
+        print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+        a = list(py_iterator())
+        print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])
+        a = list(cy_iterator())
+        print(sys.exc_info()[0] is ValueError or sys.exc_info()[0])