[pypy-commit] pypy default: merge heads
antocuni
pypy.commits at gmail.com
Tue Nov 14 20:14:27 EST 2017
Author: Antonio Cuni <anto.cuni at 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()
More information about the pypy-commit
mailing list