Author: Antonio Cuni <anto.c...@gmail.com> Branch: Changeset: r93033:821e59360f37 Date: 2017-11-15 02:13 +0100 http://bitbucket.org/pypy/pypy/changeset/821e59360f37/
Log: merge heads diff --git a/pypy/module/_continuation/test/test_stacklet.py b/pypy/module/_continuation/test/test_stacklet.py --- a/pypy/module/_continuation/test/test_stacklet.py +++ b/pypy/module/_continuation/test/test_stacklet.py @@ -340,16 +340,41 @@ import sys from _continuation import continulet # + def stack(f=None): + """ + get the call-stack of the caller or the specified frame + """ + if f is None: + f = sys._getframe(1) + res = [] + seen = set() + while f: + if f in seen: + # frame loop + res.append('...') + break + seen.add(f) + res.append(f.f_code.co_name) + f = f.f_back + #print res + return res + def bar(c): + assert stack() == ['bar', 'foo', 'test_f_back'] c.switch(sys._getframe(0)) c.switch(sys._getframe(0).f_back) c.switch(sys._getframe(1)) + # + assert stack() == ['bar', 'foo', 'main', 'test_f_back'] c.switch(sys._getframe(1).f_back) + # + assert stack() == ['bar', 'foo', 'main2', 'test_f_back'] assert sys._getframe(2) is f3_foo.f_back c.switch(sys._getframe(2)) def foo(c): bar(c) # + assert stack() == ['test_f_back'] c = continulet(foo) f1_bar = c.switch() assert f1_bar.f_code.co_name == 'bar' @@ -358,14 +383,20 @@ f3_foo = c.switch() assert f3_foo is f2_foo assert f1_bar.f_back is f3_foo + # def main(): f4_main = c.switch() assert f4_main.f_code.co_name == 'main' assert f3_foo.f_back is f1_bar # not running, so a loop + assert stack() == ['main', 'test_f_back'] + assert stack(f1_bar) == ['bar', 'foo', '...'] + # def main2(): f5_main2 = c.switch() assert f5_main2.f_code.co_name == 'main2' assert f3_foo.f_back is f1_bar # not running, so a loop + assert stack(f1_bar) == ['bar', 'foo', '...'] + # main() main2() res = c.switch() _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit