[pypy-svn] pypy default: Change the test. This is explicitly a detail behavior, but it

arigo commits-noreply at bitbucket.org
Sun Feb 6 19:46:53 CET 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r41662:298b828120fe
Date: 2011-02-06 19:45 +0100
http://bitbucket.org/pypy/pypy/changeset/298b828120fe/

Log:	Change the test. This is explicitly a detail behavior, but it makes
	some sense to check that we get exactly CPython's or PyPy's behavior
	based on which one we are running on.

	Not fixed yet: on PyPy, _seen_generator_finally is not set to True.
	At least the test makes more sense this way.

diff --git a/lib-python/2.7.0/test/test_sys_settrace.py b/lib-python/modified-2.7.0/test/test_sys_settrace.py
copy from lib-python/2.7.0/test/test_sys_settrace.py
copy to lib-python/modified-2.7.0/test/test_sys_settrace.py
--- a/lib-python/2.7.0/test/test_sys_settrace.py
+++ b/lib-python/modified-2.7.0/test/test_sys_settrace.py
@@ -210,7 +210,7 @@
         yield True
         "continued"
     finally:
-        "finally"
+        global _seen_generator_finally; _seen_generator_finally = True
 def generator_example():
     # any() will leave the generator before its end
     x = any(generator_function())
@@ -219,16 +219,20 @@
     for x in range(10):
         y = x
 
+# On CPython, when the generator is decref'ed to zero, we see the trace
+# for the "finally:" portion.  On PyPy (and likely other implementations),
+# we don't see it.
+has_finally_in_trace = test_support.check_impl_detail(cpython=True)
 generator_example.events = ([(0, 'call'),
                              (2, 'line'),
                              (-6, 'call'),
                              (-5, 'line'),
                              (-4, 'line'),
-                             (-4, 'return'),
-                             (-4, 'call'),
+                             (-4, 'return')] +
+                            [(-4, 'call'),
                              (-4, 'exception'),
                              (-1, 'line'),
-                             (-1, 'return')] +
+                             (-1, 'return')] * has_finally_in_trace +
                             [(5, 'line'), (6, 'line')] * 10 +
                             [(5, 'line'), (5, 'return')])
 
@@ -323,15 +327,22 @@
         self.run_test(tighterloop_example)
 
     def test_13_genexp(self):
+        global _seen_generator_finally
+        _seen_generator_finally = False
         self.run_test(generator_example)
+        test_support.gc_collect()
+        assert _seen_generator_finally
         # issue1265: if the trace function contains a generator,
         # and if the traced function contains another generator
         # that is not completely exhausted, the trace stopped.
         # Worse: the 'finally' clause was not invoked.
         tracer = Tracer()
+        _seen_generator_finally = False
         sys.settrace(tracer.traceWithGenexp)
         generator_example()
         sys.settrace(None)
+        test_support.gc_collect()
+        assert _seen_generator_finally
         self.compare_events(generator_example.__code__.co_firstlineno,
                             tracer.events, generator_example.events)
 


More information about the Pypy-commit mailing list