Author: Amaury Forgeot d'Arc <amaur...@gmail.com>
Branch: py3.3
Changeset: r72610:9e797b4a53ee
Date: 2014-07-29 17:43 +0200
http://bitbucket.org/pypy/pypy/changeset/9e797b4a53ee/

Log:    Implement faulthandler.enable() and disable()

diff --git a/pypy/module/faulthandler/__init__.py 
b/pypy/module/faulthandler/__init__.py
--- a/pypy/module/faulthandler/__init__.py
+++ b/pypy/module/faulthandler/__init__.py
@@ -6,5 +6,7 @@
 
     interpleveldefs = {
         'enable': 'interp_faulthandler.enable',
+        'disable': 'interp_faulthandler.disable',
+        'is_enabled': 'interp_faulthandler.is_enabled',
         'register': 'interp_faulthandler.register',
     }
diff --git a/pypy/module/faulthandler/interp_faulthandler.py 
b/pypy/module/faulthandler/interp_faulthandler.py
--- a/pypy/module/faulthandler/interp_faulthandler.py
+++ b/pypy/module/faulthandler/interp_faulthandler.py
@@ -1,5 +1,15 @@
-def enable(space, __args__):
-    pass
+class FatalErrorState(object):
+    def __init__(self, space):
+        self.enabled = False
+
+def enable(space):
+    space.fromcache(FatalErrorState).enabled = True
+
+def disable(space):
+    space.fromcache(FatalErrorState).enabled = False
+
+def is_enabled(space):
+    return space.wrap(space.fromcache(FatalErrorState).enabled)
 
 def register(space, __args__):
     pass
diff --git a/pypy/module/faulthandler/test/test_faulthander.py 
b/pypy/module/faulthandler/test/test_faulthander.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/faulthandler/test/test_faulthander.py
@@ -0,0 +1,11 @@
+class AppTestFaultHandler:
+    spaceconfig = {
+        "usemodules": ["faulthandler"]
+    }
+
+    def test_enable(self):
+        import faulthandler
+        faulthandler.enable()
+        assert faulthandler.is_enabled() is True
+        faulthandler.disable()
+        assert faulthandler.is_enabled() is False
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to