##// END OF EJS Templates
Fix terminals with Tornado 3...
Fix terminals with Tornado 3 The websocket handler auth checking was calling clear_cookie(), which threw an error because it doesn't make sense for Websockets. It doesn't seem important, and we silence it in our other websocket handlers, so silencing it here too.

File last commit:

r15605:adb71c39
r18546:2b2243ed
Show More
test_events.py
45 lines | 1.3 KiB | text/x-python | PythonLexer
Thomas Kluyver
Add tests for callback infrastructure
r15601 import unittest
try: # Python 3.3 +
from unittest.mock import Mock
except ImportError:
from mock import Mock
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 from IPython.core import events
Thomas Kluyver
Add tests for callback infrastructure
r15601 import IPython.testing.tools as tt
def ping_received():
pass
class CallbackTests(unittest.TestCase):
def setUp(self):
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em = events.EventManager(get_ipython(), {'ping_received': ping_received})
Thomas Kluyver
Add tests for callback infrastructure
r15601
def test_register_unregister(self):
cb = Mock()
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.register('ping_received', cb)
self.em.trigger('ping_received')
Thomas Kluyver
Add tests for callback infrastructure
r15601 self.assertEqual(cb.call_count, 1)
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.unregister('ping_received', cb)
self.em.trigger('ping_received')
Thomas Kluyver
Add tests for callback infrastructure
r15601 self.assertEqual(cb.call_count, 1)
def test_reset(self):
cb = Mock()
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.register('ping_received', cb)
self.em.reset('ping_received')
self.em.trigger('ping_received')
Thomas Kluyver
Add tests for callback infrastructure
r15601 assert not cb.called
def test_reset_all(self):
cb = Mock()
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.register('ping_received', cb)
self.em.reset_all()
self.em.trigger('ping_received')
Thomas Kluyver
Add tests for callback infrastructure
r15601 assert not cb.called
def test_cb_error(self):
cb = Mock(side_effect=ValueError)
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.register('ping_received', cb)
Thomas Kluyver
Add tests for callback infrastructure
r15601 with tt.AssertPrints("Error in callback"):
Thomas Kluyver
Rename callbacks -> events (mostly), fire -> trigger
r15605 self.em.trigger('ping_received')