[pypy-commit] pypy fix-vmprof-stacklet-switch-2: make check_status a real method, so that it can be tested and used also without the fixture

antocuni pypy.commits at gmail.com
Tue Nov 28 11:50:10 EST 2017


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: fix-vmprof-stacklet-switch-2
Changeset: r93196:d3c13697bffe
Date: 2017-11-28 17:00 +0100
http://bitbucket.org/pypy/pypy/changeset/d3c13697bffe/

Log:	make check_status a real method, so that it can be tested and used
	also without the fixture

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
@@ -1,4 +1,5 @@
 import os
+from rpython.rlib.rvmprof.test.support import fakevmprof
 from pypy.module._continuation.test.support import BaseAppTest
 
 
diff --git a/rpython/rlib/rvmprof/test/support.py b/rpython/rlib/rvmprof/test/support.py
--- a/rpython/rlib/rvmprof/test/support.py
+++ b/rpython/rlib/rvmprof/test/support.py
@@ -26,17 +26,20 @@
     def is_sampling_enabled(self):
         return self._ignore_signals == 0
 
+    def check_status(self):
+        """
+        To be called during test teardown
+        """
+        if self._ignore_signals != 1:
+            msg = ('Invalid value for fakevmprof._ignore_signals: expected 1, '
+                   'got %d. This probably means that you called '
+                   '{start,stop}_sampling() a wrong number of times')
+            raise ValueError, msg % self._ignore_signals
+
 
 @pytest.fixture
 def fakevmprof(request, monkeypatch):
     fake = FakeVMProf()
     monkeypatch.setattr(rvmprof.rvmprof, '_vmprof_instance', fake)
-    #
-    def check_status():
-        if fake._ignore_signals != 1:
-            msg = ('Invalid value for fakevmprof._ignore_signals: expected 1, '
-                   'got %d. This probably means that you called '
-                   '{start,stop}_sampling() a wrong number of times')
-            raise ValueError, msg % fake._ignore_signals
-    request.addfinalizer(check_status)
+    request.addfinalizer(fake.check_status)
     return fake
diff --git a/rpython/rlib/rvmprof/test/test_support.py b/rpython/rlib/rvmprof/test/test_support.py
--- a/rpython/rlib/rvmprof/test/test_support.py
+++ b/rpython/rlib/rvmprof/test/test_support.py
@@ -22,6 +22,10 @@
         #
         pytest.raises(AssertionError, "fake.start_sampling()")
     
+    def test_check_status(self):
+        fake = FakeVMProf()
+        fake.stop_sampling()
+        pytest.raises(ValueError, "fake.check_status()")
 
 
 class TestFixture(object):


More information about the pypy-commit mailing list