##// END OF EJS Templates
Remove EventManager reset methods, because they violate encapsulation....
Remove EventManager reset methods, because they violate encapsulation. The whole idea of the EventManager is that you can register hooks without worrying about what hooks other pieces of code might be registering. The reset methods violate this separation of concerns, since they will blow away everyone else's hooks too. (See gh-6680 for an example of this breaking things.) Since there is never any safe way to use them, we simply remove them entirely.

File last commit:

r18547:4043b271
r18547:4043b271
Show More
test_events.py
32 lines | 929 B | text/x-python | PythonLexer
import unittest
try: # Python 3.3 +
from unittest.mock import Mock
except ImportError:
from mock import Mock
from IPython.core import events
import IPython.testing.tools as tt
def ping_received():
pass
class CallbackTests(unittest.TestCase):
def setUp(self):
self.em = events.EventManager(get_ipython(), {'ping_received': ping_received})
def test_register_unregister(self):
cb = Mock()
self.em.register('ping_received', cb)
self.em.trigger('ping_received')
self.assertEqual(cb.call_count, 1)
self.em.unregister('ping_received', cb)
self.em.trigger('ping_received')
self.assertEqual(cb.call_count, 1)
def test_cb_error(self):
cb = Mock(side_effect=ValueError)
self.em.register('ping_received', cb)
with tt.AssertPrints("Error in callback"):
self.em.trigger('ping_received')