[pypy-commit] pypy fix-vmprof-stacklet-switch-2: rename the fixture to app_fakevmprof and use it on all tests: this way, it automatically checks that {start, stop}_sampling has been called an even amount of times
antocuni
pypy.commits at gmail.com
Tue Nov 28 11:50:14 EST 2017
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fix-vmprof-stacklet-switch-2
Changeset: r93198:a48521eb6944
Date: 2017-11-28 17:30 +0100
http://bitbucket.org/pypy/pypy/changeset/a48521eb6944/
Log: rename the fixture to app_fakevmprof and use it on all tests: this
way, it automatically checks that {start,stop}_sampling has been
called an even amount of times
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
@@ -4,7 +4,7 @@
from pypy.interpreter.gateway import interp2app
from pypy.module._continuation.test.support import BaseAppTest
-
+ at pytest.mark.usefixtures('app_fakevmprof')
class AppTestStacklet(BaseAppTest):
def setup_class(cls):
BaseAppTest.setup_class.im_func(cls)
@@ -41,6 +41,29 @@
# make sure that "self.stack" does not pass the self
cls.w_stack = staticmethod(cls.w_stack.im_func)
+
+ @pytest.fixture
+ def app_fakevmprof(self, fakevmprof):
+ """
+ This is automaticaly re-initialized for every method: thanks to
+ fakevmprof's finalizer, it checks that we called {start,stop}_sampling
+ the in pairs
+ """
+ w = self.space.wrap
+ i2a = interp2app
+ def is_sampling_enabled(space):
+ return space.wrap(fakevmprof.is_sampling_enabled)
+ self.w_is_sampling_enabled = w(i2a(is_sampling_enabled))
+ #
+ def start_sampling(space):
+ fakevmprof.start_sampling()
+ self.w_start_sampling = w(i2a(start_sampling))
+ #
+ def stop_sampling(space):
+ fakevmprof.stop_sampling()
+ self.w_stop_sampling = w(i2a(stop_sampling))
+
+
def test_new_empty(self):
from _continuation import continulet
#
@@ -774,29 +797,6 @@
continulet.switch(c1, to=c2)
raises(error, continulet.switch, c1, to=c2)
-
- at pytest.mark.usefixtures('init_method')
-class AppTestVMProf(BaseAppTest):
-
- @pytest.fixture
- def init_method(self, fakevmprof):
- """
- This is automaticaly re-initialized for every method
- """
- w = self.space.wrap
- i2a = interp2app
- def is_sampling_enabled(space):
- return space.wrap(fakevmprof.is_sampling_enabled)
- self.w_is_sampling_enabled = w(i2a(is_sampling_enabled))
- #
- def start_sampling(space):
- fakevmprof.start_sampling()
- self.w_start_sampling = w(i2a(start_sampling))
- #
- def stop_sampling(space):
- fakevmprof.stop_sampling()
- self.w_stop_sampling = w(i2a(stop_sampling))
-
def test_sampling_inside_callback(self):
from _continuation import continulet
#
@@ -804,10 +804,12 @@
assert self.is_sampling_enabled()
return 42
#
- self.start_sampling()
- assert self.is_sampling_enabled()
- c = continulet(my_callback)
- res = c.switch()
- assert res == 42
- assert self.is_sampling_enabled()
- self.stop_sampling()
+ try:
+ self.start_sampling()
+ assert self.is_sampling_enabled()
+ c = continulet(my_callback)
+ res = c.switch()
+ assert res == 42
+ assert self.is_sampling_enabled()
+ finally:
+ self.stop_sampling()
More information about the pypy-commit
mailing list