##// END OF EJS Templates
Add setting to disable venv warning (#13706)...
Add setting to disable venv warning (#13706) * Add setting to disable venv warning * Fix style * Add what's new entry * Improve help text * Use double quotes Co-authored-by: Blazej Michalik <6691643+MrMino@users.noreply.github.com> * Add missing comma Co-authored-by: Blazej Michalik <6691643+MrMino@users.noreply.github.com>

File last commit:

r26892:8f530016
r27697:66aeb3fc master
Show More
test_events.py
91 lines | 2.7 KiB | text/x-python | PythonLexer
Thomas Kluyver
Add tests for callback infrastructure
r15601 import unittest
Srinivas Reddy Thatiparthy
remove code specific to python2
r23063 from unittest.mock import Mock
Thomas Kluyver
Add tests for callback infrastructure
r15601
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
Fabio Niephaus
Use `backcall` and introduce `ExecutionRequest`
r23996
Fabio Niephaus
Ensure post event callbacks are always called....
r23982 @events._define_event
Thomas Kluyver
Add tests for callback infrastructure
r15601 def ping_received():
pass
Fabio Niephaus
Use `backcall` and introduce `ExecutionRequest`
r23996
Fabio Niephaus
Ensure post event callbacks are always called....
r23982 @events._define_event
def event_with_argument(argument):
pass
Fabio Niephaus
Use `backcall` and introduce `ExecutionRequest`
r23996
Thomas Kluyver
Add tests for callback infrastructure
r15601 class CallbackTests(unittest.TestCase):
def setUp(self):
Thomas A Caswell
STY: line wrap test init to make more readable
r24014 self.em = events.EventManager(get_ipython(),
{'ping_received': ping_received,
'event_with_argument': event_with_argument})
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)
Thomas A Caswell
TST: add test for searching for removal with bare functions
r24013
def test_bare_function_missed_unregister(self):
def cb1():
...
def cb2():
...
Samuel Gaist
[core][tests][events] Remove nose
r26892 self.em.register("ping_received", cb1)
self.assertRaises(ValueError, self.em.unregister, "ping_received", cb2)
self.em.unregister("ping_received", cb1)
Thomas A Caswell
TST: add test for searching for removal with bare functions
r24013
Thomas Kluyver
Add tests for callback infrastructure
r15601 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"):
Nathaniel J. Smith
Remove EventManager reset methods, because they violate encapsulation....
r18547 self.em.trigger('ping_received')
Craig Citro
Make event triggering robust to (un)registration....
r22317
jsnydes
address #11630 by catching KeyboardInterrupt from event handlers
r24961 def test_cb_keyboard_interrupt(self):
cb = Mock(side_effect=KeyboardInterrupt)
self.em.register('ping_received', cb)
jsnydes
fix new test
r24962 with tt.AssertPrints("Error in callback"):
jsnydes
address #11630 by catching KeyboardInterrupt from event handlers
r24961 self.em.trigger('ping_received')
Craig Citro
Make event triggering robust to (un)registration....
r22317 def test_unregister_during_callback(self):
invoked = [False] * 3
def func1(*_):
invoked[0] = True
self.em.unregister('ping_received', func1)
self.em.register('ping_received', func3)
def func2(*_):
invoked[1] = True
self.em.unregister('ping_received', func2)
def func3(*_):
invoked[2] = True
self.em.register('ping_received', func1)
self.em.register('ping_received', func2)
self.em.trigger('ping_received')
self.assertEqual([True, True, False], invoked)
self.assertEqual([func3], self.em.callbacks['ping_received'])
Fabio Niephaus
Ensure post event callbacks are always called....
r23982
def test_ignore_event_arguments_if_no_argument_required(self):
call_count = [0]
def event_with_no_argument():
call_count[0] += 1
Fabio Niephaus
Use `backcall` and introduce `ExecutionRequest`
r23996 self.em.register('event_with_argument', event_with_no_argument)
Fabio Niephaus
Ensure post event callbacks are always called....
r23982 self.em.trigger('event_with_argument', 'the argument')
self.assertEqual(call_count[0], 1)
self.em.unregister('event_with_argument', event_with_no_argument)
self.em.trigger('ping_received')
self.assertEqual(call_count[0], 1)