cython
1# mode: run
2# tag: generator
3
4import cython5import sys6
7
8def test_generator_frame_cycle():9"""10>>> test_generator_frame_cycle()
11("I'm done",)
12"""
13testit = []14def whoo():15try:16yield17except:18yield19finally:20testit.append("I'm done")21g = whoo()22next(g)23
24# Frame object cycle25eval('g.throw(ValueError)', {'g': g})26del g27
28return tuple(testit)29
30
31def test_generator_frame_cycle_with_outer_exc():32"""33>>> test_generator_frame_cycle_with_outer_exc()
34("I'm done",)
35"""
36testit = []37def whoo():38try:39yield40except:41yield42finally:43testit.append("I'm done")44g = whoo()45next(g)46
47try:48raise ValueError()49except ValueError as exc:50assert sys.exc_info()[1] is exc, sys.exc_info()51# Frame object cycle52eval('g.throw(ValueError)', {'g': g})53# CPython 3.3 handles this incorrectly itself :)54assert sys.exc_info()[1] is exc, sys.exc_info()55del g56assert sys.exc_info()[1] is exc, sys.exc_info()57
58return tuple(testit)59