[pypy-commit] pypy default: improve the test by also checking the full call-stack at various points. Probably it does not test anything more than before, but it is a good aid when you read it

antocuni pypy.commits at gmail.com
Tue Nov 14 20:14:13 EST 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: 
Changeset: r93027:b7758cca88a3
Date: 2017-11-13 18:40 +0100
http://bitbucket.org/pypy/pypy/changeset/b7758cca88a3/

Log:	improve the test by also checking the full call-stack at various
	points. Probably it does not test anything more than before, but it
	is a good aid when you read it

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